public static IQueryExecutionBuilder AddErrorFilter <T>(
     this IQueryExecutionBuilder builder)
     where T : class, IErrorFilter
 {
     builder.Services.AddSingleton <IErrorFilter, T>();
     return(builder);
 }
Ejemplo n.º 2
0
        public static IQueryExecutionBuilder UseInstrumentation(
            this IQueryExecutionBuilder builder,
            TracingPreference tracingPreference)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var listener = new DiagnosticListener(DiagnosticNames.Listener);

            builder
            .RemoveService <DiagnosticListener>()
            .RemoveService <DiagnosticSource>();
            builder.Services
            .AddSingleton(listener)
            .AddSingleton <DiagnosticSource>(listener)
            .AddSingleton(sp => new QueryExecutionDiagnostics(
                              sp.GetRequiredService <DiagnosticListener>(),
                              sp.GetServices <IDiagnosticObserver>()));

            if (tracingPreference != TracingPreference.Never)
            {
                builder
                .AddDiagnosticObserver(new ApolloTracingDiagnosticObserver(
                                           tracingPreference));
            }

            return(builder.Use <InstrumentationMiddleware>());
        }
Ejemplo n.º 3
0
        public static IQueryExecutionBuilder MapField(
            this IQueryExecutionBuilder builder,
            FieldReference fieldReference,
            FieldMiddleware middleware)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

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

            return(builder.UseField(
                       FieldClassMiddlewareFactory.Create <MapMiddleware>(
                           (s, n) => new MapMiddleware(
                               n, fieldReference, middleware(n)))));
        }
        public static IQueryExecutionBuilder AddDefaultValidationRules(
            this IQueryExecutionBuilder builder)
        {
            builder.Services.AddDefaultValidationRules();

            return(builder);
        }
Ejemplo n.º 5
0
        public static IQueryExecutionBuilder AddOptions(
            this IQueryExecutionBuilder builder,
            IQueryExecutionOptionsAccessor options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            builder
            .RemoveService <IQueryExecutionOptionsAccessor>()
            .RemoveService <IErrorHandlerOptionsAccessor>()
            .RemoveService <IInstrumentationOptionsAccessor>()
            .RemoveService <IQueryCacheSizeOptionsAccessor>()
            .RemoveService <IRequestTimeoutOptionsAccessor>()
            .RemoveService <IValidateQueryOptionsAccessor>();
            builder.Services.AddOptions(options);

            return(builder);
        }
        public static IQueryExecutionBuilder UseQueryDelegationPipeline(
            this IQueryExecutionBuilder builder,
            IQueryExecutionOptionsAccessor options,
            string schemaName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            if (string.IsNullOrEmpty(schemaName))
            {
                throw new ArgumentException(
                          "The schema name mustn't be null or empty.",
                          nameof(schemaName));
            }

            return(builder
                   .AddOptions(options)
                   .AddErrorHandler()
                   .AddDefaultParser()
                   .UseRequestTimeout()
                   .UseExceptionHandling()
                   .UseRemoteQueryExecutor(schemaName));
        }
 public static IQueryExecutionBuilder UseStitchingPipeline(
     this IQueryExecutionBuilder builder)
 {
     return(UseStitchingPipeline(
                builder,
                new QueryExecutionOptions()));
 }
Ejemplo n.º 8
0
        public static IQueryExecutionBuilder UseInstrumentation(
            this IQueryExecutionBuilder builder,
            IInstrumentationOptionsAccessor options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            builder.Services
            .AddSingleton(options)
            .AddScoped <DiagnosticListenerInitializer>();

            if (options.EnableTracing)
            {
                builder.Services
                .AddScoped <
                    IApolloTracingResultBuilder,
                    ApolloTracingResultBuilder>()
                .AddScoped <
                    DiagnosticListener,
                    ApolloTracingDiagnosticListener>();
            }

            return(builder.Use <InstrumentationMiddleware>());
        }
Ejemplo n.º 9
0
        public static IQueryExecutionBuilder UseDefaultPipeline(
            this IQueryExecutionBuilder builder,
            IQueryExecutionOptionsAccessor options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(builder
                   .AddErrorHandler(options)
                   .AddQueryValidation(options)
                   .AddDefaultValidationRules()
                   .AddQueryCache(options)
                   .AddExecutionStrategyResolver()
                   .AddDefaultParser()
                   .UseInstrumentation(options)
                   .UseRequestTimeout(options)
                   .UseExceptionHandling()
                   .UseQueryParser()
                   .UseValidation()
                   .UseOperationResolver()
                   .UseCoerceVariables()
                   .UseOperationExecuter());
        }
        public static IQueryExecutionBuilder UseStitchingPipeline(
            this IQueryExecutionBuilder builder,
            IQueryExecutionOptionsAccessor options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            return(builder
                   .AddDefaultServices(options)
                   .UseDefaultDiagnostics(options)
                   .UseQueryParser()
                   .UseNoCachedQueryError()
                   .UseValidation()
                   .UseOperationResolver()
                   .UseMaxComplexity()
                   .UsePropagateVariables()
                   .UseOperationExecutor());
        }
Ejemplo n.º 11
0
        public static IQueryExecutionBuilder MapField <TMiddleware>(
            this IQueryExecutionBuilder builder,
            FieldReference fieldReference,
            Func <IServiceProvider, FieldDelegate, TMiddleware> factory)
            where TMiddleware : class
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

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

            return(builder.UseField(
                       FieldClassMiddlewareFactory.Create <MapMiddleware>(
                           (s, n) =>
            {
                FieldMiddleware classMiddleware =
                    FieldClassMiddlewareFactory.Create(factory);

                return new MapMiddleware(
                    n, fieldReference, classMiddleware(n));
            })));
        }
Ejemplo n.º 12
0
        public static IQueryExecutionBuilder UseDefaultPipeline(
            this IQueryExecutionBuilder builder,
            IQueryExecutionOptionsAccessor options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            return(builder
                   .AddOptions(options)
                   .AddErrorHandler()
                   .AddQueryValidation()
                   .AddDefaultValidationRules()
                   .AddQueryCache(options.QueryCacheSize)
                   .AddExecutionStrategyResolver()
                   .AddDefaultParser()
                   .UseInstrumentation(options.TracingPreference)
                   .UseRequestTimeout()
                   .UseExceptionHandling()
                   .UseQueryParser()
                   .UseValidation()
                   .UseOperationResolver()
                   .UseMaxComplexity()
                   .UseOperationExecutor());
        }
Ejemplo n.º 13
0
 public static IQueryExecutionBuilder UseField <TMiddleware>(
     this IQueryExecutionBuilder builder,
     Func <IServiceProvider, FieldDelegate, TMiddleware> factory)
     where TMiddleware : class
 {
     return(builder.UseField(
                FieldClassMiddlewareFactory.Create <TMiddleware>(factory)));
 }
Ejemplo n.º 14
0
        public static IQueryExecutionBuilder AddValidationRule(
            this IQueryExecutionBuilder builder,
            Func <IServiceProvider, IQueryValidationRule> factory)
        {
            builder.Services.AddSingleton(factory);

            return(builder);
        }
Ejemplo n.º 15
0
        public static IQueryExecutionBuilder AddQueryValidation(
            this IQueryExecutionBuilder builder,
            IValidateQueryOptionsAccessor options)
        {
            builder.Services.AddQueryValidation(options);

            return(builder);
        }
Ejemplo n.º 16
0
        public static IQueryExecutionBuilder AddValidationRule <T>(
            this IQueryExecutionBuilder builder)
            where T : class, IQueryValidationRule
        {
            builder.Services.AddSingleton <IQueryValidationRule, T>();

            return(builder);
        }
 private static IQueryExecutionBuilder UseDefaultDiagnostics(
     this IQueryExecutionBuilder builder,
     IInstrumentationOptionsAccessor options)
 {
     return(builder
            .UseInstrumentation(options.TracingPreference)
            .UseRequestTimeout()
            .UseExceptionHandling());
 }
Ejemplo n.º 18
0
 public static IQueryExecutionBuilder UseQueryDelegationPipeline(
     this IQueryExecutionBuilder builder,
     string schemaName)
 {
     return(UseQueryDelegationPipeline(
                builder,
                new QueryExecutionOptions(),
                schemaName));
 }
 public static IQueryExecutionBuilder AddMD5DocumentHashProvider(
     this IQueryExecutionBuilder builder,
     HashFormat format)
 {
     builder.RemoveService <IDocumentHashProvider>();
     builder.Services.AddSingleton <IDocumentHashProvider>(
         new MD5DocumentHashProvider(format));
     return(builder);
 }
Ejemplo n.º 20
0
        public static IQueryExecutionBuilder AddParser <T>(
            this IQueryExecutionBuilder builder)
            where T : class, IQueryParser
        {
            builder.RemoveService <IQueryParser>();
            builder.Services.AddSingleton <IQueryParser, T>();

            return(builder);
        }
Ejemplo n.º 21
0
 public static IQueryExecutionBuilder AddSha256DocumentHashProvider(
     this IQueryExecutionBuilder builder)
 {
     builder.RemoveService <IDocumentHashProvider>();
     builder.Services.AddSingleton <
         IDocumentHashProvider,
         Sha256DocumentHashProvider>();
     return(builder);
 }
Ejemplo n.º 22
0
        public static IQueryExecutor MakeExecutable(
            this ISchema schema,
            Func <IQueryExecutionBuilder, IQueryExecutionBuilder> configure)
        {
            IQueryExecutionBuilder builder = configure(
                QueryExecutionBuilder.New());

            return(builder.Build(schema));
        }
 public static IQueryExecutionBuilder AddExecutionStrategyResolver(
     this IQueryExecutionBuilder builder)
 {
     builder.RemoveService <IExecutionStrategyResolver>();
     builder.Services.AddSingleton <
         IExecutionStrategyResolver,
         ExecutionStrategyResolver>();
     return(builder);
 }
Ejemplo n.º 24
0
        private static IQueryExecutionBuilder RemoveService <TService>(
            this IQueryExecutionBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.RemoveService(typeof(TService)));
        }
Ejemplo n.º 25
0
        public static IQueryExecutionBuilder UseExceptionHandling(
            this IQueryExecutionBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.Use <ExceptionMiddleware>());
        }
Ejemplo n.º 26
0
        public static IQueryExecutionBuilder AddDefaultParser(
            this IQueryExecutionBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(AddParser <DefaultQueryParser>(builder));
        }
Ejemplo n.º 27
0
        public static IQueryExecutionBuilder UseMaxComplexity(
            this IQueryExecutionBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.Use <MaxComplexityMiddleware>());
        }
Ejemplo n.º 28
0
        public static IQueryExecutionBuilder UseValidation(
            this IQueryExecutionBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.Use <ValidateQueryMiddleware>());
        }
Ejemplo n.º 29
0
        public static IQueryExecutionBuilder UseRequestTimeout(
            this IQueryExecutionBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.Use <RequestTimeoutMiddleware>());
        }
Ejemplo n.º 30
0
        public static IQueryExecutionBuilder UseOperationResolver(
            this IQueryExecutionBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.Use <ResolveOperationMiddleware>());
        }