diff --git a/src/VirtoCommerce.Xapi.Core/Extensions/ApplicationBuilderExtensions.cs b/src/VirtoCommerce.Xapi.Core/Extensions/ApplicationBuilderExtensions.cs index c352258..2544178 100644 --- a/src/VirtoCommerce.Xapi.Core/Extensions/ApplicationBuilderExtensions.cs +++ b/src/VirtoCommerce.Xapi.Core/Extensions/ApplicationBuilderExtensions.cs @@ -1,11 +1,22 @@ using GraphQL.Server.Ui.Playground; using GraphQL.Types; using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using VirtoCommerce.Xapi.Core.Infrastructure; +using VirtoCommerce.Xapi.Core.Models; namespace VirtoCommerce.Xapi.Core.Extensions; public static class ApplicationBuilderExtensions { + public static IApplicationBuilder UseScopedSchema(this IApplicationBuilder builder, string schemaPath) + { + var playgroundOptions = builder.ApplicationServices.GetService>(); + + return builder.UseSchemaGraphQL>(playgroundOptions?.Value?.Enable ?? true, schemaPath); + } + public static IApplicationBuilder UseSchemaGraphQL(this IApplicationBuilder builder, bool schemaIntrospectionEnabled = true, string schemaPath = null) where TSchema : ISchema { @@ -15,15 +26,15 @@ public static IApplicationBuilder UseSchemaGraphQL(this IApplicationBui graphQlPath = $"{graphQlPath}/{schemaPath}"; } - var playgroundPath = "/ui/playground"; - if (!string.IsNullOrEmpty(schemaPath)) - { - playgroundPath = $"{playgroundPath}/{schemaPath}"; - } - builder.UseGraphQL(path: graphQlPath); if (schemaIntrospectionEnabled) { + var playgroundPath = "/ui/playground"; + if (!string.IsNullOrEmpty(schemaPath)) + { + playgroundPath = $"{playgroundPath}/{schemaPath}"; + } + builder.UseGraphQLPlayground(new PlaygroundOptions { GraphQLEndPoint = graphQlPath,