-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VCST-2241: prepare schema for partition (#18)
- Loading branch information
1 parent
e3bf4a5
commit 8e8a463
Showing
7 changed files
with
110 additions
and
27 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/VirtoCommerce.Xapi.Core/Extensions/ApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using GraphQL.Server.Ui.Playground; | ||
using GraphQL.Types; | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace VirtoCommerce.Xapi.Core.Extensions; | ||
|
||
public static class ApplicationBuilderExtensions | ||
{ | ||
public static IApplicationBuilder UseSchemaGraphQL<TSchema>(this IApplicationBuilder builder, bool schemaIntrospectionEnabled = true, string schemaPath = null) | ||
where TSchema : ISchema | ||
{ | ||
var graphQlPath = "/graphql"; | ||
if (!string.IsNullOrEmpty(schemaPath)) | ||
{ | ||
graphQlPath = $"{graphQlPath}/{schemaPath}"; | ||
} | ||
|
||
var playgroundPath = "/ui/playground"; | ||
if (!string.IsNullOrEmpty(schemaPath)) | ||
{ | ||
playgroundPath = $"{playgroundPath}/{schemaPath}"; | ||
} | ||
|
||
builder.UseGraphQL<TSchema>(path: graphQlPath); | ||
if (schemaIntrospectionEnabled) | ||
{ | ||
builder.UseGraphQLPlayground(new PlaygroundOptions | ||
{ | ||
GraphQLEndPoint = graphQlPath, | ||
}, | ||
path: playgroundPath); | ||
} | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/VirtoCommerce.Xapi.Core/Infrastructure/ScopedSchemaFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 inside this assembly | ||
var currentAssembly = typeof(TMarker).Assembly; | ||
|
||
var subSchemaBuilders = schemaBuilders | ||
.Where(p => p.GetType().Assembly == currentAssembly) | ||
.ToList(); | ||
|
||
return subSchemaBuilders; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters