コード例 #1
0
        public static IServiceCollection AddGraphQLWithName(
            this IServiceCollection services,
            string schemaName,
            Action <ISchemaConfiguration> configure,
            Action <IQueryExecutionBuilder> build)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            QueryExecutionBuilder builder = QueryExecutionBuilder.New();

            build(builder);
            builder.Populate(schemaName, services);

            return(services.AddSchema(schemaName, s => Schema.Create(c =>
            {
                c.RegisterServiceProvider(s);
                configure(c);
            }))
                   .AddBatchQueryExecutor(schemaName));
        }
コード例 #2
0
        public static IServiceCollection AddGraphQL(
            this IServiceCollection services,
            Action <ISchemaConfiguration> configure,
            Func <IQueryExecutionBuilder, IQueryExecutionBuilder>
            configureBuilder)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            configureBuilder(QueryExecutionBuilder.New())
            .Populate(services);
            return(services.AddSchema(s => Schema.Create(c =>
            {
                c.RegisterServiceProvider(s);
                configure(c);
            }))
                   .AddSingleton <IBatchQueryExecutor, BatchQueryExecutor>());
        }
コード例 #3
0
        public static IServiceCollection AddGraphQL(
            this IServiceCollection services,
            Func <IServiceProvider, ISchema> schemaFactory,
            Action <IQueryExecutionBuilder> build)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            QueryExecutionBuilder builder = QueryExecutionBuilder.New();

            build(builder);
            builder.Populate(services);

            return(services.AddSchema(schemaFactory)
                   .AddSingleton <IBatchQueryExecutor, BatchQueryExecutor>());
        }
コード例 #4
0
        public async Task VerifyCustomDignosticObserverIsWorkingProper()
        {
            // arrange
            var events = new List <string>();

            Schema schema = CreateSchema();

            IQueryExecutor executor = QueryExecutionBuilder.New()
                                      .UseDefaultPipeline()
                                      .AddDiagnosticObserver(new CustomDiagnosticsObserver(events))
                                      .Build(schema);

            IReadOnlyQueryRequest request =
                QueryRequestBuilder.New()
                .SetQuery("{ a }")
                .Create();

            // act
            IExecutionResult result = await executor.ExecuteAsync(request);

            // assert
            Assert.Empty(result.Extensions);
            Assert.Collection(events,
                              i => Assert.Equal("foo", i),
                              i => Assert.Equal("bar", i));
        }
コード例 #5
0
        public static IServiceCollection AddGraphQLWithName(
            this IServiceCollection services,
            string schemaName,
            ISchema schema,
            Action <IQueryExecutionBuilder> build)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            QueryExecutionBuilder builder = QueryExecutionBuilder.New();

            build(builder);
            builder.Populate(schemaName, services);

            return(services.AddSchema(schemaName, schema)
                   .AddBatchQueryExecutor(schemaName));
        }
コード例 #6
0
        public static IServiceCollection AddGraphQL(
            this IServiceCollection services,
            string schemaSource,
            Action <ISchemaConfiguration> configure,
            Action <IQueryExecutionBuilder> build)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (string.IsNullOrEmpty(schemaSource))
            {
                throw new ArgumentNullException(nameof(schemaSource));
            }

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

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

            QueryExecutionBuilder builder = QueryExecutionBuilder.New();

            build(builder);
            builder.Populate(services);

            return(services.AddGraphQLWithName(string.Empty, schemaSource, configure, build));
        }
コード例 #7
0
 public QueryExecutorBenchmarkBase(int cacheSize)
 {
     _schema        = SchemaFactory.Create();
     _queryExecutor = QueryExecutionBuilder.New()
                      .UseDefaultPipeline()
                      .AddQueryCache(cacheSize)
                      .Build(_schema);
 }
コード例 #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            //services.AddGraphQL(SchemaBuilder.New());

            /*
             * This is an alternative approach (workaround) to fix this behavior
             */
            #region Workaround

            Func <IServiceProvider, ISchema> factory = s => SchemaBuilder.New()
                                                       .AddServices(s)
                                                       .AddType <AuthorType>()
                                                       .AddType <BookType>()
                                                       .AddQueryType <Query>()
                                                       .Create();

            var opts = new QueryExecutionOptions {
            };

            services.AddSingleton(sp =>
            {
                var d = sp.GetRequiredService <DiagnosticListener>();
                var o = sp.GetServices <IDiagnosticObserver>();

                BindingFlags flags   = BindingFlags.NonPublic | BindingFlags.Instance;
                CultureInfo culture  = null;
                var instantiatedType = Activator.CreateInstance(typeof(QueryExecutionDiagnostics), flags, null, new object[] { d, o }, culture);
                return(instantiatedType as QueryExecutionDiagnostics);
            });

            QueryExecutionBuilder.New()
            .AddDefaultServices(opts)
            .UseRequestTimeout()
            .UseExceptionHandling()


            .UseQueryParser()
            .UseNoCachedQueryError()
            .UseValidation()
            .UseOperationResolver()
            .UseMaxComplexity()
            .UseOperationExecutor()
            .Populate(services);

            services.AddSingleton(factory);
            services.AddSingleton <IIdSerializer, IdSerializer>()
            .AddGraphQLSubscriptions();
            services.AddJsonQueryResultSerializer().AddJsonArrayResponseStreamSerializer();

            services.AddSingleton <IBatchQueryExecutor, BatchQueryExecutor>();

            /* END */
            #endregion

            services.AddApplicationInsightsTelemetry();
        }
コード例 #9
0
        public static IQueryExecutor MakeExecutable(
            this ISchema schema,
            Action <IQueryExecutionBuilder> configure)
        {
            QueryExecutionBuilder builder = QueryExecutionBuilder.New();

            configure(builder);
            return(builder.Build(schema));
        }
コード例 #10
0
        public static IQueryExecutor MakeExecutable(
            this ISchema schema,
            Func <IQueryExecutionBuilder, IQueryExecutionBuilder> configure)
        {
            IQueryExecutionBuilder builder = configure(
                QueryExecutionBuilder.New());

            return(builder.Build(schema));
        }
コード例 #11
0
        public static IServiceCollection AddQueryExecutor(
            this IServiceCollection services,
            Action <IQueryExecutionBuilder> configure)
        {
            var builder = QueryExecutionBuilder.New();

            configure(builder);
            builder.Populate(services);
            return(services);
        }
コード例 #12
0
 public static async Task <IExecutionResult> ExecuteAsync(
     this ISchema schema, QueryRequest request,
     CancellationToken cancellationToken = default)
 {
     using (IQueryExecuter executer = QueryExecutionBuilder.New()
                                      .UseDefaultPipeline().Build(schema))
     {
         return(await executer.ExecuteAsync(request, cancellationToken));
     }
 }
コード例 #13
0
        public void Populate(IServiceCollection serviceCollection)
        {
            if (serviceCollection == null)
            {
                throw new ArgumentNullException(nameof(serviceCollection));
            }

            serviceCollection.TryAddSingleton <
                IQueryResultSerializer,
                JsonQueryResultSerializer>();

            foreach (KeyValuePair <NameString, ExecutorFactory> factory in
                     _execFacs)
            {
                serviceCollection.AddSingleton <IRemoteExecutorAccessor>(
                    services => new RemoteExecutorAccessor(
                        factory.Key,
                        factory.Value.Invoke(services)));
            }

            serviceCollection.TryAddSingleton(services =>
                                              StitchingFactory.Create(this, services));

            serviceCollection.TryAddScoped(services =>
                                           services.GetRequiredService <StitchingFactory>()
                                           .CreateStitchingContext(services));

            if (!serviceCollection.Any(d =>
                                       d.ImplementationType == typeof(RemoteQueryBatchOperation)))
            {
                serviceCollection.AddScoped <
                    IBatchOperation,
                    RemoteQueryBatchOperation>();
            }

            serviceCollection.TryAddSingleton <ISchema>(sp =>
                                                        sp.GetRequiredService <StitchingFactory>()
                                                        .CreateStitchedSchema(sp));

            var builder = QueryExecutionBuilder.New();

            foreach (Action <IQueryExecutionBuilder> configure in _execConfigs)
            {
                configure(builder);
            }
            builder.UseStitchingPipeline();
            builder.Populate(serviceCollection, true);

            serviceCollection.TryAddSingleton(services =>
                                              services.GetRequiredService <IQueryExecutor>()
                                              .Schema);
        }
コード例 #14
0
        public static IServiceCollection AddGraphQL(
            this IServiceCollection serviceCollection,
            BuildExecuter buildExecuter)
        {
            if (buildExecuter == null)
            {
                throw new ArgumentNullException(nameof(buildExecuter));
            }

            return(serviceCollection
                   .AddSingleton <IQueryExecuter>(s =>
                                                  buildExecuter(s, QueryExecutionBuilder.New()))
                   .AddSingleton(s =>
                                 s.GetRequiredService <IQueryExecuter>().Schema)
                   .AddJsonSerializer());
        }
コード例 #15
0
        public static IServiceCollection AddGraphQL(
            this IServiceCollection serviceCollection,
            Func <IServiceProvider, ISchema> schemaFactory,
            Func <IQueryExecutionBuilder, IQueryExecutionBuilder> configure)
        {
            if (serviceCollection == null)
            {
                throw new ArgumentNullException(nameof(serviceCollection));
            }

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

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

            configure(QueryExecutionBuilder.New()).Populate(serviceCollection);
            return(serviceCollection.AddSchema(schemaFactory));
        }
コード例 #16
0
        public static IServiceCollection AddGraphQL(
            this IServiceCollection serviceCollection,
            string schemaSource,
            Action <ISchemaConfiguration> configure,
            Func <IQueryExecutionBuilder, IQueryExecutionBuilder>
            configureBuilder)
        {
            if (serviceCollection == null)
            {
                throw new ArgumentNullException(nameof(serviceCollection));
            }

            if (string.IsNullOrEmpty(schemaSource))
            {
                throw new ArgumentNullException(nameof(schemaSource));
            }

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

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

            configureBuilder(QueryExecutionBuilder.New())
            .Populate(serviceCollection);

            return(serviceCollection.AddSchema(s =>
                                               Schema.Create(schemaSource, c =>
            {
                c.RegisterServiceProvider(s);
                configure(c);
            })));
        }
コード例 #17
0
        public static IServiceCollection AddGraphQL(
            this IServiceCollection services,
            ISchema schema,
            Func <IQueryExecutionBuilder, IQueryExecutionBuilder> configure)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            configure(QueryExecutionBuilder.New()).Populate(services);
            return(services.AddSchema(schema)
                   .AddSingleton <IBatchQueryExecutor, BatchQueryExecutor>());
        }