Skip to content

Commit

Permalink
feat: prepare schema for partition
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev committed Nov 19, 2024
1 parent c69a36d commit e8de831
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/VirtoCommerce.Xapi.Core/Infrastructure/SchemaFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GraphQL;
using GraphQL.Conversion;
using GraphQL.Instrumentation;
Expand Down Expand Up @@ -61,14 +62,9 @@ public SchemaFactory(IEnumerable<ISchemaBuilder> 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);
Expand Down Expand Up @@ -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<ISchemaBuilder> GetSchemaBuilders()
{
return _schemaBuilders.ToList();
}

public void Initialize()
{
_schema.Value.Initialize();
Expand Down

0 comments on commit e8de831

Please sign in to comment.