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

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

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

            var executer = (IQueryExecuter)serviceProvider
                           .GetService(typeof(IQueryExecuter));

            var serializer = (IQueryResultSerializer)serviceProvider
                             .GetService(typeof(IQueryResultSerializer))
                             ?? new JsonQueryResultSerializer();

            return(applicationBuilder
                   .Use <PostQueryMiddleware>(executer, serializer, options)
                   .Use <GetQueryMiddleware>(executer, serializer, options)
                   //.Use<SubscriptionMiddleware>(executer, options)
                   .Use <SchemaMiddleware>(executer, options));
        }
Exemple #2
0
        /// <summary>
        /// Instantiates the base query middleware with an optional pointer to
        /// the next component.
        /// </summary>
        /// <param name="next">
        /// An optional pointer to the next component.
        /// </param>
        /// <param name="queryExecutor">
        /// A required query executor resolver.
        /// </param>
        /// <param name="resultSerializer">
        /// </param>
        /// <param name="options">
        /// </param>
        protected QueryMiddlewareBase(
            RequestDelegate next,
            IQueryExecutor queryExecutor,
            IQueryResultSerializer resultSerializer,
            QueryMiddlewareOptions options)
#if ASPNETCLASSIC
            : base(next)
#endif
        {
#if !ASPNETCLASSIC
            Next = next;
#endif
            Executor = queryExecutor ??
                       throw new ArgumentNullException(nameof(queryExecutor));
            _resultSerializer = resultSerializer
                                ?? throw new ArgumentNullException(nameof(resultSerializer));
            Options = options ??
                      throw new ArgumentNullException(nameof(options));

            if (Options.Path.Value.Length > 1)
            {
                var        path1 = new PathString(options.Path.Value.TrimEnd('/'));
                PathString path2 = path1.Add(new PathString("/"));
                _isPathValid = ctx => ctx.IsValidPath(path1, path2);
            }
            else
            {
                _isPathValid = ctx => ctx.IsValidPath(options.Path);
            }
        }
 public GetQueryMiddleware(
     RequestDelegate next,
     IQueryExecuter queryExecuter,
     QueryMiddlewareOptions options)
     : base(next, queryExecuter, options)
 {
 }
Exemple #4
0
        internal TestServer Create(
            QueryMiddlewareOptions options,
            IConfiguration configuration,
            Action <HttpContext> onRequestFinish)
        {
            IWebHostBuilder builder = new WebHostBuilder()
                                      .Configure(app => app
                                                 .Use(async(context, next) =>
            {
                await next.Invoke();
                onRequestFinish?.Invoke(context);
            })
                                                 .UseGraphQL(options))
                                      .ConfigureServices(services =>
            {
                services
                .AddSingleton <IStartupFilter, TestStartupFilter>()
                .AddGraphQL(c => c.RegisterQueryType <QueryType>())
                .AddSingleton <IAttachmentTransmissionInitializer>(
                    provider =>
                    new AttachmentTransmissionInitializer(
                        Enumerable.Empty <ITelemetryAttachmentTransmitter>()))
                .AddTracingHttpMessageHandler(configuration)
                .AddInProcessTelemetrySession(configuration)
                .AddTracingMinimum(configuration)
                .AddHotChocolateTracing();
            });

            var server = new TestServer(builder);

            _instances.Add(server);
            return(server);
        }
Exemple #5
0
        public TestServer Create(
            Action <ISchemaConfiguration> configure,
            Action <IServiceCollection> configureServices,
            QueryMiddlewareOptions options)
        {
            var server = TestServer.Create(appBuilder =>
            {
                var httpConfig        = new HttpConfiguration();
                var serviceCollection = new ServiceCollection();

                configureServices?.Invoke(serviceCollection);
                serviceCollection.AddScoped <TestService>();
                serviceCollection.AddGraphQL(configure);

                IServiceProvider serviceProvider = serviceCollection
                                                   .BuildServiceProvider();

                httpConfig.DependencyResolver =
                    new DefaultDependencyResolver(serviceProvider);
                appBuilder.UseGraphQL(serviceProvider, options);
            });

            _instances.Add(server);

            return(server);
        }
Exemple #6
0
 public PostQueryMiddleware(
     RequestDelegate next,
     IQueryExecutor queryExecutor,
     IQueryResultSerializer resultSerializer,
     QueryMiddlewareOptions options)
     : base(next, queryExecutor, resultSerializer, options)
 {
 }
        public void DefaultParserOptionsAreSet()
        {
            // arrange
            var options = new QueryMiddlewareOptions();

            // act
            ParserOptions parserOptions = options.ParserOptions;

            // assert
            Assert.NotNull(parserOptions);
        }
        public void SetEmptyPathString()
        {
            // arrange
            var options = new QueryMiddlewareOptions();

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

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

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

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

            // act
            options.ParserOptions = parserOptions;

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

            return(applicationBuilder
                   .UseGraphQL(options));
        }
Exemple #12
0
        public static void ConfigureQuery <TService>(PipelineBuilder <TService, QueryContext <TService> > builder)
            where TService : BaseDomainService
        {
            QueryMiddlewareOptions <TService> middlewareOptions = new QueryMiddlewareOptions <TService>();

            builder.UseMiddleware <QueryMiddleware.AuthorizeMiddleware <TService>, TService, QueryContext <TService> >(middlewareOptions);
            builder.UseMiddleware <QueryMiddleware.ExecuteMiddleware <TService>, TService, QueryContext <TService> >(middlewareOptions);

            builder.Run(ctx =>
            {
                return(Task.CompletedTask);
            });
        }
 public PostQueryMiddleware(
     RequestDelegate next,
     IQueryExecutor queryExecutor,
     IQueryResultSerializer resultSerializer,
     IDocumentCache documentCache,
     IDocumentHashProvider documentHashProvider,
     QueryMiddlewareOptions options)
     : base(next, queryExecutor, resultSerializer, options)
 {
     _requestHelper = new RequestHelper(
         documentCache,
         documentHashProvider,
         options.MaxRequestSize,
         options.ParserOptions);
 }
        /// <summary>
        /// Instantiates the base query middleware with an optional pointer to
        /// the next component.
        /// </summary>
        /// <param name="next">
        /// An optional pointer to the next component.
        /// </param>
        /// <param name="queryExecuterResolver">
        /// A required query executor resolver.
        /// </param>
        /// <param name="options">
        /// </param>
        protected QueryMiddlewareBase(
            RequestDelegate next,
            IQueryExecuter queryExecuter,
            QueryMiddlewareOptions options)
#if ASPNETCLASSIC
            : base(next)
#endif
        {
#if !ASPNETCLASSIC
            Next = next;
#endif
            _queryExecuter = queryExecuter ??
                             throw new ArgumentNullException(nameof(queryExecuter));
            Options = options ??
                      throw new ArgumentNullException(nameof(options));
            Services = Executer.Schema.Services;
        }
        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)
                   .UseMiddleware <SubscriptionMiddleware>(options));
        }
        public SchemaMiddleware(
            RequestDelegate next,
            IQueryExecutor queryExecutor,
            QueryMiddlewareOptions options)
#if ASPNETCLASSIC
            : base(next)
#endif
        {
#if !ASPNETCLASSIC
            Next = next;
#endif
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _queryExecutor = queryExecutor
                             ?? throw new ArgumentNullException(nameof(queryExecutor));
            _path = options.Path.Add(new PathString("/schema"));
        }
        public static IApplicationBuilder UseGraphQL(
            this IApplicationBuilder applicationBuilder,
            IServiceProvider serviceProvider,
            QueryMiddlewareOptions options)
        {
            if (applicationBuilder == null)
            {
                throw new ArgumentNullException(nameof(applicationBuilder));
            }

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

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

            return(applicationBuilder
                   .UseGraphQLHttpPost(serviceProvider,
                                       new HttpPostMiddlewareOptions
            {
                Path = options.Path,
                ParserOptions = options.ParserOptions,
                MaxRequestSize = options.MaxRequestSize
            })
                   .UseGraphQLHttpGet(serviceProvider,
                                      new HttpGetMiddlewareOptions
            {
                Path = options.Path
            })
                   .UseGraphQLHttpGetSchema(serviceProvider,
                                            new HttpGetSchemaMiddlewareOptions
            {
                Path = options.Path.Add(new PathString("/schema"))
            }));
        }
Exemple #18
0
        public static IApplicationBuilder UseGraphQL(
            this IApplicationBuilder applicationBuilder,
            IServiceProvider serviceProvider,
            QueryMiddlewareOptions options)
        {
            if (applicationBuilder == null)
            {
                throw new ArgumentNullException(nameof(applicationBuilder));
            }

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

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

            IQueryExecutor executor = serviceProvider
                                      .GetService <IQueryExecutor>();

            IQueryResultSerializer serializer = serviceProvider
                                                .GetService <IQueryResultSerializer>()
                                                ?? new JsonQueryResultSerializer();

            IDocumentCache cache = serviceProvider
                                   .GetRequiredService <IDocumentCache>();

            IDocumentHashProvider hashProvider = serviceProvider
                                                 .GetRequiredService <IDocumentHashProvider>();

            return(applicationBuilder
                   .Use <PostQueryMiddleware>(executor, serializer, cache, hashProvider, options)
                   .Use <GetQueryMiddleware>(executor, serializer, options)
                   .Use <SchemaMiddleware>(executor, options));
        }
Exemple #19
0
 public TestServer Create(
     Action <ISchemaConfiguration> configure,
     QueryMiddlewareOptions options)
 {
     return(Create(configure, null, options));
 }