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); }
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); }
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(); }