public static IServiceCollection AddGraphQL( this IServiceCollection serviceCollection, Func <IServiceProvider, ISchema> schemaFactory, IQueryExecutionOptionsAccessor options) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } if (schemaFactory == null) { throw new ArgumentNullException(nameof(schemaFactory)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(serviceCollection .AddSingleton(schemaFactory) .AddSingleton(sp => sp.GetRequiredService <ISchema>() .MakeExecutable(options)) .AddJsonSerializer()); }
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()); }
public async Task RequestDataLoader() { // arrange ISchema schema = CreateSchema(ExecutionScope.Request); IQueryExecutionOptionsAccessor options = CreateOptions(); IQueryExecuter executer = QueryExecutionBuilder .BuildDefault(schema, options); // act List <IExecutionResult> results = new List <IExecutionResult>(); results.Add(await executer.ExecuteAsync(new QueryRequest( @"{ a: withDataLoader(key: ""a"") b: withDataLoader(key: ""b"") }"))); results.Add(await executer.ExecuteAsync(new QueryRequest( @"{ a: withDataLoader(key: ""a"") }"))); results.Add(await executer.ExecuteAsync(new QueryRequest( @"{ c: withDataLoader(key: ""c"") }"))); results.Add(await executer.ExecuteAsync(new QueryRequest( "{ loads }"))); // assert Assert.Collection(results, t => Assert.Null(t.Errors), t => Assert.Null(t.Errors), t => Assert.Null(t.Errors), t => Assert.Null(t.Errors)); results.Snapshot(); }
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 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 IServiceCollection AddQueryExecutor( this IServiceCollection services, IQueryExecutionOptionsAccessor options) { QueryExecutionBuilder.BuildDefault(services, options); return(services); }
public static IServiceCollection AddGraphQL( this IServiceCollection serviceCollection, ISchema schema, IQueryExecutionOptionsAccessor options) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } if (schema == null) { throw new ArgumentNullException(nameof(schema)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(serviceCollection .AddSingleton(schema) .AddSingleton(schema.MakeExecutable(options)) .AddJsonSerializer()); }
public static IServiceCollection AddGraphQLWithName( this IServiceCollection services, string schemaName, Action <ISchemaConfiguration> configure, IQueryExecutionOptionsAccessor options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } QueryExecutionBuilder.BuildDefault(services, schemaName, options); return(services.AddSchema(schemaName, s => Schema.Create(c => { c.RegisterServiceProvider(s); configure(c); })) .AddBatchQueryExecutor(schemaName)); }
public static IServiceCollection AddStitchedSchema( this IServiceCollection services, string schema, IQueryExecutionOptionsAccessor options) { return(AddStitchedSchema(services, schema, c => { }, options)); }
public static IServiceCollection AddGraphQLWitName( this IServiceCollection services, string schemaName, Func <IServiceProvider, ISchema> schemaFactory, IQueryExecutionOptionsAccessor options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (schemaFactory == null) { throw new ArgumentNullException(nameof(schemaFactory)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } QueryExecutionBuilder.BuildDefault(services, schemaName, options); return(services.AddSchema(schemaName, schemaFactory) .AddBatchQueryExecutor(schemaName)); }
public static IServiceCollection AddGraphQL( this IServiceCollection services, Action <ISchemaConfiguration> configure, IQueryExecutionOptionsAccessor options) { return(services.AddGraphQLWithName(string.Empty, configure, options)); }
public static IServiceCollection AddGraphQL( this IServiceCollection services, ISchema schema, IQueryExecutionOptionsAccessor options) { return(services.AddGraphQLWithName(string.Empty, schema, options)); }
public static IServiceCollection AddGraphQL( this IServiceCollection services, Func <IServiceProvider, ISchema> schemaFactory, IQueryExecutionOptionsAccessor options) { return(services.AddGraphQLWitName(string.Empty, schemaFactory, options)); }
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()); }
public static IServiceCollection AddGraphQL( this IServiceCollection serviceCollection, string schemaSource, Action <ISchemaConfiguration> configure, IQueryExecutionOptionsAccessor options) { 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 (options == null) { throw new ArgumentNullException(nameof(options)); } QueryExecutionBuilder.BuildDefault(serviceCollection, options); return(serviceCollection.AddSchema(s => Schema.Create(schemaSource, c => { c.RegisterServiceProvider(s); configure(c); }))); }
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 IServiceCollection AddGraphQL( this IServiceCollection serviceCollection, Action <ISchemaConfiguration> configure, IQueryExecutionOptionsAccessor options) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(serviceCollection .AddSingleton <ISchema>(s => Schema.Create(c => { c.RegisterServiceProvider(s); configure(c); })) .AddSingleton(sp => sp.GetRequiredService <ISchema>() .MakeExecutable(options)) .AddJsonSerializer()); }
private StitchingFactory( StitchingBuilder builder, IReadOnlyList <IRemoteExecutorAccessor> executors, DocumentNode mergedSchema) { _builder = builder; _executors = executors; MergedSchema = mergedSchema; _options = _builder._options ?? new QueryExecutionOptions(); }
public IStitchingBuilder SetExecutionOptions( IQueryExecutionOptionsAccessor options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } _options = options; return(this); }
private static IQueryValidator CreateValidator( IQueryExecutionOptionsAccessor options) { IServiceCollection services = new ServiceCollection() .AddOptions(options) .AddQueryValidation() .AddDefaultValidationRules(); return(services .BuildServiceProvider() .GetRequiredService <IQueryValidator>()); }
private static IQueryExecutionBuilder AddDefaultServices( this IQueryExecutionBuilder builder, IQueryExecutionOptionsAccessor options) { return(builder .AddOptions(options) .AddErrorHandler() .AddQueryValidation() .AddDefaultValidationRules() .AddQueryCache(options.QueryCacheSize) .AddExecutionStrategyResolver() .AddDefaultParser() .AddDefaultDocumentHashProvider()); }
public async Task GlobalDataLoader() { // arrange ISchema schema = CreateSchema(ExecutionScope.Global); IQueryExecutionOptionsAccessor options = CreateOptions(); IQueryExecuter executer = QueryExecutionBuilder .BuildDefault(schema, options); // act List <IExecutionResult> results = new List <IExecutionResult>(); results.Add(await executer.ExecuteAsync(new QueryRequest( @"{ a: withDataLoader(key: ""a"") b: withDataLoader(key: ""b"") }"))); results.Add(await executer.ExecuteAsync(new QueryRequest( @"{ a: withDataLoader(key: ""a"") }"))); results.Add(await executer.ExecuteAsync(new QueryRequest( @"{ c: withDataLoader(key: ""c"") }"))); // assert Assert.Collection(results, t => Assert.Null(t.Errors), t => Assert.Null(t.Errors), t => Assert.Null(t.Errors)); results.Snapshot(); var keyLoads = new HashSet <string>(); var loads = (IQueryExecutionResult)await executer .ExecuteAsync(new QueryRequest("{ loads }")); foreach (object o in (IEnumerable <object>)loads.Data["loads"]) { string[] keys = o.ToString().Split(','); foreach (string key in keys) { Assert.True(keyLoads.Add(key)); } } }
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 .UsePropagateVariables() .UseDefaultPipeline(options)); }
public static IQueryExecutionBuilder UseActivePersistedQueryPipeline( this IQueryExecutionBuilder builder, IQueryExecutionOptionsAccessor options) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(builder .UsePersistedQueryPipeline(options) .UseWritePersistedQuery()); }
public static IServiceCollection AddStitchedSchema( this IServiceCollection services, string schema, Action <ISchemaConfiguration> configure, IQueryExecutionOptionsAccessor options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (string.IsNullOrEmpty(schema)) { throw new ArgumentException( "The schema mustn't be null or empty.", nameof(schema)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } services.TryAddSingleton < IQueryResultSerializer, JsonQueryResultSerializer>(); return(services.AddSingleton(sp => { return Schema.Create( schema, c => { configure(c); c.UseSchemaStitching(); c.RegisterServiceProvider(sp); }) .MakeExecutable(b => b.UseStitchingPipeline(options)); }) .AddSingleton(sp => sp.GetRequiredService <IQueryExecutor>().Schema)); }
public static IServiceCollection AddOptions( this IServiceCollection services, IQueryExecutionOptionsAccessor options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(services .AddSingleton(options) .AddSingleton <IErrorHandlerOptionsAccessor>(options) .AddSingleton <IInstrumentationOptionsAccessor>(options) .AddSingleton <IQueryCacheSizeOptionsAccessor>(options) .AddSingleton <IRequestTimeoutOptionsAccessor>(options) .AddSingleton <IValidateQueryOptionsAccessor>(options)); }
public static IServiceCollection AddGraphQL( this IServiceCollection serviceCollection, Func <IServiceProvider, ISchema> schemaFactory, IQueryExecutionOptionsAccessor options) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } if (schemaFactory == null) { throw new ArgumentNullException(nameof(schemaFactory)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } QueryExecutionBuilder.BuildDefault(serviceCollection, options); return(serviceCollection.AddSchema(schemaFactory)); }
public static IQueryExecutionBuilder UsePersistedQueryPipeline( 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() .UseReadPersistedQuery() .UseValidation() .UseOperationResolver() .UseMaxComplexity() .UseOperationExecutor(); }
public static IServiceCollection AddGraphQL( this IServiceCollection services, ISchema schema, IQueryExecutionOptionsAccessor options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (schema == null) { throw new ArgumentNullException(nameof(schema)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } QueryExecutionBuilder.BuildDefault(services, options); return(services.AddSchema(schema) .AddSingleton <IBatchQueryExecutor, BatchQueryExecutor>()); }
public static IQueryExecutionBuilder AddDefaultServices( this IQueryExecutionBuilder builder, IQueryExecutionOptionsAccessor options) { IValidationBuilder validation = builder.Services.AddValidation(); if (options.MaxExecutionDepth.HasValue) { validation.AddMaxExecutionDepthRule(options.MaxExecutionDepth.Value); } if (options.MaxOperationComplexity.HasValue) { validation.AddMaxComplexityRule(options.MaxOperationComplexity.Value); } return builder .AddOptions(options) .AddErrorHandler() .AddQueryCache(options.QueryCacheSize) .AddExecutionStrategyResolver() .AddDefaultParser() .AddDefaultDocumentHashProvider(); }