コード例 #1
0
 private static IApplicationBuilder UsePlaygroundSettingsMiddleware(
     this IApplicationBuilder applicationBuilder,
     PlaygroundOptions options)
 {
     return(applicationBuilder.Map(
                options.Path.Add(new PathString("/settings.js")),
                app => app.UseMiddleware <SettingsMiddleware>(options)));
 }
コード例 #2
0
 // ReSharper disable once SuggestBaseTypeForParameter
 public FormatController(
     IWebHostEnvironment webHostEnvironment,
     ILogger <FormatController> logger,
     IOptions <PlaygroundOptions> options)
 {
     this.webHostEnvironment = webHostEnvironment;
     this.logger             = logger;
     this.options            = options.Value;
 }
コード例 #3
0
        public void SubscriptionPath_Set_To_Empty_ArgumentException()
        {
            // arrange
            var options = new PlaygroundOptions();

            // act
            Action action = () => options.SubscriptionPath = default;

            // act
            Assert.Throws <ArgumentException>(action);
        }
コード例 #4
0
        public void SetGraphQLEndpoint()
        {
            // arrange
            var options = new PlaygroundOptions();

            // act
            options.GraphQLEndpoint = new Uri("https://localhost:5000/graphql");

            // act
            Assert.Equal("https://localhost:5000/graphql", options.GraphQLEndpoint.AbsoluteUri);
        }
コード例 #5
0
        public void Default_Values()
        {
            // arrange
            // act
            var options = new PlaygroundOptions();

            // act
            Assert.Equal("/playground", options.Path);
            Assert.Equal("/", options.QueryPath);
            Assert.Equal("/", options.SubscriptionPath);
        }
コード例 #6
0
        public void SetPath()
        {
            // arrange
            var options = new PlaygroundOptions();

            // act
            options.Path = new PathString("/foo");

            // act
            Assert.Equal("/foo", options.Path.ToString());
            Assert.Equal("/", options.QueryPath.ToString());
            Assert.Equal("/", options.SubscriptionPath.ToString());
        }
コード例 #7
0
        public void SetQueryPath()
        {
            // arrange
            var options = new PlaygroundOptions();

            // act
            options.QueryPath = "/foo";

            // act
            Assert.Equal("/foo/playground", options.Path);
            Assert.Equal("/foo", options.QueryPath);
            Assert.Equal("/foo", options.SubscriptionPath);
        }
コード例 #8
0
        public void GraphQLEndpoint_Set_To_Null_Or_Invalid_Exceptions()
        {
            // arrange
            var options = new PlaygroundOptions();

            // act
            Action invalidUriAction = () => options.GraphQLEndpoint = new Uri("not a uri");
            Action nullUriAction    = () => options.GraphQLEndpoint = new Uri(null);

            // act
            Assert.Throws <UriFormatException>(invalidUriAction);
            Assert.Throws <ArgumentNullException>(nullUriAction);
        }
コード例 #9
0
        public static IApplicationBuilder UsePlayground(
            this IApplicationBuilder applicationBuilder,
            PlaygroundOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(applicationBuilder
                   .UsePlaygroundSettingsMiddleware(options)
                   .UsePlaygroundFileServer(options.Path));
        }
コード例 #10
0
        public async Task Default_Values()
        {
            // arrange
            var options = new PlaygroundOptions();

            TestServer server      = CreateServer(options);
            string     settingsUri = "/playground/settings.js";

            // act
            string settings_js = await GetSettingsAsync(server, settingsUri);

            // act
            settings_js.MatchSnapshot();
        }
コード例 #11
0
        public async Task Disable_Subscriptions()
        {
            // arrange
            var options = new PlaygroundOptions();

            options.EnableSubscription = false;

            TestServer server      = CreateServer(options);
            string     settingsUri = "/playground/settings.js";

            // act
            string settings_js = await GetSettingsAsync(server, settingsUri);

            // act
            settings_js.MatchSnapshot();
        }
コード例 #12
0
        public async Task SetQueryPath()
        {
            // arrange
            var options = new PlaygroundOptions();

            options.QueryPath = "/foo";

            TestServer server      = CreateServer(options);
            string     settingsUri = "/foo/playground/settings.js";

            // act
            string settings_js = await GetSettingsAsync(server, settingsUri);

            // act
            settings_js.MatchSnapshot();
        }
コード例 #13
0
        public async Task SetGraphQLEndpointWithSubscriptions()
        {
            // arrange
            var options = new PlaygroundOptions();

            options.Path            = "/bar";
            options.GraphQLEndpoint = new Uri("https://microsoft.com/graphql");

            TestServer server      = CreateServer(options);
            string     settingsUri = "/bar/settings.js";

            // act
            string settings_js = await GetSettingsAsync(server, settingsUri);

            // act
            settings_js.MatchSnapshot();
        }
コード例 #14
0
        public async Task SetGraphQLEndpoint()
        {
            // arrange
            var options = new PlaygroundOptions();

            options.EnableSubscription = false;
            options.Path            = "/foo-bar";
            options.GraphQLEndpoint = new Uri("https://hotchocolate.io/graphql");

            TestServer server      = CreateServer(options);
            string     settingsUri = "/foo-bar/settings.js";

            // act
            string settings_js = await GetSettingsAsync(server, settingsUri);

            // act
            settings_js.MatchSnapshot();
        }
コード例 #15
0
        public SettingsMiddleware(
            RequestDelegate next,
            PlaygroundOptions options)
#if ASPNETCLASSIC
            : base(next)
#endif
        {
#if !ASPNETCLASSIC
            Next = next;
#endif
            _options = options
                       ?? throw new ArgumentNullException(nameof(options));

            Uri uiPath           = UriFromPath(options.Path);
            Uri queryPath        = UriFromPath(options.QueryPath);
            Uri subscriptionPath = UriFromPath(options.SubscriptionPath);

            _queryPath        = uiPath.MakeRelativeUri(queryPath).ToString();
            _subscriptionPath = uiPath.MakeRelativeUri(subscriptionPath)
                                .ToString();
        }
コード例 #16
0
 // ReSharper disable once UnusedParameter.Local
 public PlaygroundTenantMiddleware(RequestDelegate next, IOspService ospService, PlaygroundOptions options)
 {
     _ospService = ospService;
     _options    = options ?? throw new ArgumentNullException(nameof(options));
 }
コード例 #17
0
 public PlaygroundPageModel(string graphQlEndPoint, PlaygroundOptions options)
 {
     _graphQlEndPoint = graphQlEndPoint;
     _options         = options;
 }
コード例 #18
0
    /// <summary>
    /// Add the Playground middleware to the HTTP request pipeline
    /// </summary>
    /// <param name="endpoints">Defines a contract for a route builder in an application. A route builder specifies the routes for an application.</param>
    /// <param name="options">Options to customize <see cref="PlaygroundMiddleware"/>. If not set, then the default values will be used.</param>
    /// <param name="pattern">The route pattern.</param>
    /// <returns>The <see cref="IApplicationBuilder"/> received as parameter</returns>
    public static PlaygroundEndpointConventionBuilder MapGraphQLPlayground(this IEndpointRouteBuilder endpoints, PlaygroundOptions options, string pattern = "ui/playground")
    {
        if (endpoints == null)
        {
            throw new ArgumentNullException(nameof(endpoints));
        }

        var requestDelegate = endpoints.CreateApplicationBuilder().UseMiddleware <PlaygroundMiddleware>(options ?? new PlaygroundOptions()).Build();

        return(new PlaygroundEndpointConventionBuilder(endpoints.MapGet(pattern, requestDelegate).WithDisplayName("GraphQL Playground")));
    }
コード例 #19
0
 private TestServer CreateServer(PlaygroundOptions options)
 {
     return(ServerFactory.Create(
                services => services.AddStarWars(),
                app => app.UseGraphQL().UsePlayground(options)));
 }
コード例 #20
0
 public PlaygroundMiddleware(RequestDelegate next, PlaygroundOptions options)
 {
     _options = options ?? throw new ArgumentNullException(nameof(options));
 }
コード例 #21
0
 /// <summary> Adds middleware for GraphQL Playground using the specified options. </summary>
 /// <param name="app"> <see cref="IApplicationBuilder"/> to configure an application's request pipeline. </param>
 /// <param name="options"> Options to customize <see cref="PlaygroundMiddleware"/>. If not set, then the default values will be used. </param>
 /// <param name="path">The path to the GraphQL Playground endpoint which defaults to '/ui/playground'</param>
 /// <returns> The reference to provided <paramref name="app"/> instance. </returns>
 public static IApplicationBuilder UseGraphQLPlayground(this IApplicationBuilder app, PlaygroundOptions options, string path = "/ui/playground")
 {
     return(app.UseWhen(
                context => context.Request.Path.StartsWithSegments(path, out var remaining) && string.IsNullOrEmpty(remaining),
                b => b.UseMiddleware <PlaygroundMiddleware>(options ?? new PlaygroundOptions())));
 }
コード例 #22
0
 public PlaygroundPageModel(PlaygroundOptions options)
 {
     _options = options;
 }