From e8de83166778f35336b1ddab56bcba60cc8b46b7 Mon Sep 17 00:00:00 2001 From: Konstantin Savosteev Date: Tue, 19 Nov 2024 15:40:21 +0200 Subject: [PATCH] feat: prepare schema for partition --- .../Infrastructure/SchemaFactory.cs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/VirtoCommerce.Xapi.Core/Infrastructure/SchemaFactory.cs b/src/VirtoCommerce.Xapi.Core/Infrastructure/SchemaFactory.cs index 37a49d8..47866f3 100644 --- a/src/VirtoCommerce.Xapi.Core/Infrastructure/SchemaFactory.cs +++ b/src/VirtoCommerce.Xapi.Core/Infrastructure/SchemaFactory.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using GraphQL; using GraphQL.Conversion; using GraphQL.Instrumentation; @@ -61,14 +62,9 @@ public SchemaFactory(IEnumerable schemaBuilders, IServiceProvide public ISchema GetSchema() { - var schema = new Schema(_services) - { - Query = new ObjectGraphType { Name = "Query" }, - Mutation = new ObjectGraphType { Name = "Mutations" }, - Subscription = new ObjectGraphType { Name = "Subscriptions" }, - Filter = _schemaFilter, - }; + var schema = CreateSchema(_services, _schemaFilter); + var schemaBuilders = GetSchemaBuilders(); foreach (var builder in _schemaBuilders) { builder.Build(schema); @@ -99,9 +95,30 @@ public ISchema GetSchema() schema.Mutation = null; } + if (schema.Subscription.Fields.Count == 0) + { + schema.Subscription = null; + } + return schema; } + protected virtual Schema CreateSchema(IServiceProvider services, ISchemaFilter schemaFilter) + { + return new Schema(services) + { + Query = new ObjectGraphType { Name = "Query" }, + Mutation = new ObjectGraphType { Name = "Mutations" }, + Subscription = new ObjectGraphType { Name = "Subscriptions" }, + Filter = schemaFilter, + }; + } + + protected virtual List GetSchemaBuilders() + { + return _schemaBuilders.ToList(); + } + public void Initialize() { _schema.Value.Initialize();