Beispiel #1
0
        public GraphQLSchema BuildSchema(IEnumerable <ISchemaEntity> schemas)
        {
            var schemaInfos = SchemaInfo.Build(schemas).ToList();

            foreach (var schemaInfo in schemaInfos)
            {
                var contentType = new ContentGraphType(this, schemaInfo);

                contentTypes[schemaInfo]       = contentType;
                contentResultTypes[schemaInfo] = new ContentResultGraphType(contentType, schemaInfo);
            }

            var newSchema = new GraphQLSchema
            {
                Query = new AppQueriesGraphType(this, schemaInfos)
            };

            newSchema.RegisterValueConverter(JsonConverter.Instance);
            newSchema.RegisterValueConverter(InstantConverter.Instance);

            newSchema.RegisterType(sharedTypes.ContentInterface);

            if (schemas.Any())
            {
                newSchema.Mutation = new AppMutationsGraphType(this, schemaInfos);
            }

            foreach (var(schemaInfo, contentType) in contentTypes)
            {
                contentType.Initialize(this, schemaInfo, schemaInfos);
            }

            foreach (var contentType in contentTypes.Values)
            {
                newSchema.RegisterType(contentType);
            }

            newSchema.Initialize();
            newSchema.CleanupMetadata();

            return(newSchema);
        }
Beispiel #2
0
        private void InitializeContentTypes(List <ISchemaEntity> allSchemas)
        {
            var i = 0;

            foreach (var contentType in contentTypes.Values)
            {
                var schema = allSchemas[i];

                contentType.Initialize(this, schema, allSchemas);

                i++;
            }

            foreach (var contentType in contentTypes.Values)
            {
                graphQLSchema.RegisterType(contentType);
            }

            graphQLSchema.Initialize();
            graphQLSchema.CleanupMetadata();
        }