Skip to content

Commit

Permalink
feat: add scoped schema factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev committed Nov 19, 2024
1 parent e8de831 commit cfa95cf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ISchema GetSchema()
var schema = CreateSchema(_services, _schemaFilter);

var schemaBuilders = GetSchemaBuilders();
foreach (var builder in _schemaBuilders)
foreach (var builder in schemaBuilders)
{
builder.Build(schema);
}
Expand Down
32 changes: 32 additions & 0 deletions src/VirtoCommerce.Xapi.Core/Infrastructure/ScopedSchemaFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GraphQL.Introspection;

namespace VirtoCommerce.Xapi.Core.Infrastructure
{
public class ScopedSchemaFactory<TMarker> : SchemaFactory
{
public ScopedSchemaFactory(
IEnumerable<ISchemaBuilder> schemaBuilders,
IServiceProvider services,
ISchemaFilter schemaFilter)
: base(schemaBuilders, services, schemaFilter)
{
}

protected override List<ISchemaBuilder> GetSchemaBuilders()
{
var schemaBuilders = base.GetSchemaBuilders();

// find all builders with inside this project
var currentAssembly = typeof(TMarker).Assembly;

var subSchemaBuilders = schemaBuilders
.Where(p => p.GetType().Assembly == currentAssembly)
.ToList();

return subSchemaBuilders;
}
}
}

0 comments on commit cfa95cf

Please sign in to comment.