Beispiel #1
0
        public GraphQLSchema BuildSchema(IEnumerable <ISchemaEntity> schemas)
        {
            // Do not add schema without fields.
            allSchemas.AddRange(SchemaInfo.Build(schemas).Where(x => x.Fields.Count > 0));

            // Only published normal schemas (not components are used for entities).
            var schemaInfos = allSchemas.Where(x => x.Schema.SchemaDef.IsPublished && x.Schema.SchemaDef.Type != SchemaType.Component).ToList();

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

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

            foreach (var schemaInfo in allSchemas)
            {
                var componentType = new ComponentGraphType(schemaInfo);

                componentTypes[schemaInfo] = componentType;
            }

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

            newSchema.RegisterType(SharedTypes.ComponentInterface);
            newSchema.RegisterType(SharedTypes.ContentInterface);

            if (schemaInfos.Any())
            {
                var mutations = new AppMutationsGraphType(this, schemaInfos);

                if (mutations.Fields.Count > 0)
                {
                    newSchema.Mutation = mutations;
                }
            }

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

            foreach (var(schemaInfo, componentType) in componentTypes)
            {
                componentType.Initialize(this, schemaInfo);
            }

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

            newSchema.Initialize();

            return(newSchema);
        }
Beispiel #2
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 #3
0
        private void InitializeContentTypes()
        {
            foreach (var contentType in contentTypes.Values)
            {
                contentType.Initialize(this);
            }

            foreach (var contentType in contentTypes.Values)
            {
                graphQLSchema.RegisterType(contentType);
            }
        }
        private void InitializeContentTypes(List <ISchemaEntity> allSchemas, int pageSize)
        {
            var i = 0;

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

                contentType.Initialize(this, schema, allSchemas, pageSize);

                i++;
            }

            foreach (var contentType in contentTypes.Values)
            {
                graphQLSchema.RegisterType(contentType);
            }
        }
Beispiel #5
0
        private static GraphQLSchema BuildSchema(GraphQLModel model, List <ISchemaEntity> schemas)
        {
            var schema = new GraphQLSchema
            {
                Query = new AppQueriesGraphType(model, schemas)
            };

            schema.RegisterType(ContentInterfaceGraphType.Instance);

            var schemasWithFields = schemas.Where(x => x.SchemaDef.Fields.Count > 0);

            if (schemasWithFields.Any())
            {
                schema.Mutation = new AppMutationsGraphType(model, schemasWithFields);
            }

            return(schema);
        }
        public GraphQLNetSchema Convert(IGraphSchema graphSchema)
        {
            var schema = new GraphQLNetSchema();

            if (graphSchema.Query.Fields.Any())
            {
                schema.Query = CreateSchema(OperationType.Query, graphSchema.Query);
                schema.RegisterType(schema.Query);
            }
            if (graphSchema.Mutation.Fields.Any())
            {
                schema.Mutation = CreateSchema(OperationType.Mutation, graphSchema.Mutation);
            }
            if (graphSchema.Subscription.Fields.Any())
            {
                schema.Subscription = CreateSchema(OperationType.Subscription, graphSchema.Subscription);
            }
            return(schema);
        }
Beispiel #7
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();
        }