public static IApplicationBuilder UseGraphQL(
            this IApplicationBuilder applicationBuilder,
            QueryMiddlewareOptions options)
        {
            if (applicationBuilder == null)
            {
                throw new ArgumentNullException(nameof(applicationBuilder));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(applicationBuilder
                   .UseGraphQLHttpPost(new HttpPostMiddlewareOptions
            {
                Path = options.Path,
                ParserOptions = options.ParserOptions,
                MaxRequestSize = options.MaxRequestSize
            })
                   .UseGraphQLHttpGet(new HttpGetMiddlewareOptions
            {
                Path = options.Path
            })
                   .UseGraphQLHttpGetSchema(new HttpGetSchemaMiddlewareOptions
            {
                Path = options.Path.Add(new PathString("/schema"))
            })
                   .UseGraphQLSubscriptions(new SubscriptionMiddlewareOptions
            {
                ParserOptions = options.ParserOptions,
                Path = options.SubscriptionPath
            }));
        }
        public void CannotSetParserOptionsNull()
        {
            // arrange
            var options = new QueryMiddlewareOptions();

            // act
            Action action = () => options.ParserOptions = null;

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
        public void SetEmptyPathString()
        {
            // arrange
            var options = new QueryMiddlewareOptions();

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

            // assert
            Assert.Throws <ArgumentException>(action);
        }
        public void DefaultParserOptionsAreSet()
        {
            // arrange
            var options = new QueryMiddlewareOptions();

            // act
            ParserOptions parserOptions = options.ParserOptions;

            // assert
            Assert.NotNull(parserOptions);
        }
        public static IApplicationBuilder UseGraphQL(
            this IApplicationBuilder applicationBuilder,
            PathString path)
        {
            var options = new QueryMiddlewareOptions
            {
                Path = path.HasValue ? path : new PathString("/")
            };

            return(applicationBuilder
                   .UseGraphQL(options));
        }
        public void SetParserOptions()
        {
            // arrange
            var options       = new QueryMiddlewareOptions();
            var parserOptions = new ParserOptions();

            // act
            options.ParserOptions = parserOptions;

            // assert
            Assert.Equal(parserOptions, options.ParserOptions);
        }
Exemple #7
0
 public SubscriptionMiddleware(
     RequestDelegate next,
     IQueryExecuter queryExecuter,
     QueryMiddlewareOptions options)
 {
     _next = next
             ?? throw new ArgumentNullException(nameof(next));
     Executer = queryExecuter
                ?? throw new ArgumentNullException(nameof(queryExecuter));
     Options = options
               ?? throw new ArgumentNullException(nameof(options));
 }
Exemple #8
0
        public static IApplicationBuilder UseGraphQL(
            this IApplicationBuilder applicationBuilder,
            QueryMiddlewareOptions options)
        {
            if (applicationBuilder == null)
            {
                throw new ArgumentNullException(nameof(applicationBuilder));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var stringSchemeName   = options.SchemaName ?? string.Empty;
            var schemenameFunction = options.SchemaNameProvider ?? ((o) =>
            {
                return(new ValueTask <string>(stringSchemeName));
            });

            applicationBuilder
            .UseGraphQLHttpPost(new HttpPostMiddlewareOptions
            {
                Path = options.Path,
                SchemaNameProvider = schemenameFunction,
                ParserOptions      = options.ParserOptions,
                MaxRequestSize     = options.MaxRequestSize
            })
            .UseGraphQLHttpGet(new HttpGetMiddlewareOptions
            {
                SchemaNameProvider = schemenameFunction,
                Path = options.Path
            })
            .UseGraphQLHttpGetSchema(new HttpGetSchemaMiddlewareOptions
            {
                SchemaNameProvider = schemenameFunction,
                Path = options.Path.Add(new PathString("/schema"))
            });

            //if (options.EnableSubscriptions)
            //{
            //    applicationBuilder.UseGraphQLSubscriptions(
            //        new SubscriptionMiddlewareOptions
            //        {
            //            SchemaNameProvider = schemenameFunction,
            //            ParserOptions = options.ParserOptions,
            //            Path = options.SubscriptionPath
            //        });
            //}

            return(applicationBuilder);
        }
        public TestServer Create(
            ISchema schema,
            QueryMiddlewareOptions options)
        {
            IWebHostBuilder builder = new WebHostBuilder()
                                      .Configure(app => app.UseGraphQL(options))
                                      .ConfigureServices(services =>
            {
                services.AddScoped <TestService>();
                services.AddHttpContextAccessor();
                services.AddGraphQL(schema);
            });

            var server = new TestServer(builder);

            _instances.Add(server);
            return(server);
        }
Exemple #10
0
        public TestServer Create(
            Action <ISchemaConfiguration> configure,
            Action <IServiceCollection> configureServices,
            QueryMiddlewareOptions options)
        {
            IWebHostBuilder builder = new WebHostBuilder()
                                      .Configure(app => app.UseGraphQL(options))
                                      .ConfigureServices(services =>
            {
                configureServices?.Invoke(services);
                services.AddScoped <TestService>();
                services.AddGraphQL(configure);
            });

            var server = new TestServer(builder);

            _instances.Add(server);
            return(server);
        }
Exemple #11
0
        public static IApplicationBuilder UseGraphQL(
            this IApplicationBuilder applicationBuilder,
            QueryMiddlewareOptions options)
        {
            if (applicationBuilder == null)
            {
                throw new ArgumentNullException(nameof(applicationBuilder));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(applicationBuilder
                   .UseMiddleware <PostQueryMiddleware>(options)
                   .UseMiddleware <GetQueryMiddleware>(options)
                   .UseGraphQLSubscriptions(new SubscriptionMiddlewareOptions
            {
                ParserOptions = options.ParserOptions,
                SubscriptionPath = options.SubscriptionPath
            })
                   .UseMiddleware <SchemaMiddleware>(options));
        }
Exemple #12
0
 public TestServer Create(
     Action <ISchemaConfiguration> configure,
     QueryMiddlewareOptions options)
 {
     return(Create(configure, null, options));
 }