public void CloneExecutionContext() { // arrange var schema = Schema.Create( "type Query { foo: String }", c => c.Use(next => context => Task.CompletedTask)); DocumentNode query = Utf8GraphQLParser.Parse("{ foo }"); var errorHandler = new Mock <IErrorHandler>(); var services = new Mock <IServiceProvider>(); services.Setup(t => t.GetService(typeof(IErrorHandler))) .Returns(errorHandler.Object); IRequestServiceScope serviceScope = services.Object .CreateRequestServiceScope(); var variables = new Mock <IVariableValueCollection>(); var operation = new Mock <IOperation>(); operation.Setup(t => t.Document).Returns(query); operation.Setup(t => t.Variables).Returns(variables.Object); var contextData = new Dictionary <string, object> { { "abc", "123" } }; var diagnostics = new QueryExecutionDiagnostics( new DiagnosticListener("Foo"), new IDiagnosticObserver[0]); var requestContext = new RequestContext( serviceScope, (f, s) => null, new CachedQuery("{ foo }", Utf8GraphQLParser.Parse("{ foo }")), contextData, diagnostics); // act var executionContext = new ExecutionContext( schema, operation.Object, requestContext, CancellationToken.None); IExecutionContext cloned = executionContext.Clone(); // assert Assert.Equal(contextData, executionContext.ContextData); Assert.Equal(contextData, cloned.ContextData); Assert.False(object.ReferenceEquals( executionContext.Result, cloned.Result)); Assert.False(object.ReferenceEquals( executionContext.ContextData, cloned.ContextData)); }
public QueryContext( ISchema schema, IRequestServiceScope serviceScope, IReadOnlyQueryRequest request, Func <ObjectField, FieldNode, FieldDelegate> middlewareResolver, CancellationToken requestAborted) : this(schema, serviceScope, request, middlewareResolver) { RequestAborted = requestAborted; }
public SubscriptionResult( IAsyncEnumerable <object> sourceStream, Func <object, IExecutionContext> contextFactory, ExecuteSubscriptionQuery executeQuery, IRequestServiceScope serviceScope, CancellationToken cancellationToken) { _enumerator = new SubscriptionResultEnumerator( sourceStream, contextFactory, executeQuery, serviceScope, cancellationToken); }
public RequestContext( IRequestServiceScope serviceScope, Func <FieldSelection, FieldDelegate> middlewareResolver, IDictionary <string, object> contextData, QueryExecutionDiagnostics diagnostics) { ServiceScope = serviceScope ?? throw new ArgumentNullException(nameof(serviceScope)); _resolveMiddleware = middlewareResolver ?? throw new ArgumentNullException(nameof(middlewareResolver)); ContextData = contextData ?? throw new ArgumentNullException(nameof(contextData)); Diagnostics = diagnostics ?? throw new ArgumentNullException(nameof(diagnostics)); }
public SubscriptionResultEnumerator( IAsyncEnumerable <object> sourceStream, Func <object, IExecutionContext> contextFactory, ExecuteSubscriptionQuery executeQuery, IRequestServiceScope serviceScope, CancellationToken cancellationToken) { _sourceStream = sourceStream .WithCancellation(cancellationToken) .GetAsyncEnumerator(); _contextFactory = contextFactory; _executeQuery = executeQuery; _serviceScope = serviceScope; _cancellationToken = cancellationToken; serviceScope.HandleLifetime(); }
public SubscriptionResult( IEventStream eventStream, Func <IEventMessage, IExecutionContext> contextFactory, ExecuteSubscriptionQuery executeQuery, IRequestServiceScope serviceScope) { _eventStream = eventStream ?? throw new ArgumentNullException(nameof(eventStream)); _contextFactory = contextFactory ?? throw new ArgumentNullException(nameof(contextFactory)); _executeQuery = executeQuery ?? throw new ArgumentNullException(nameof(executeQuery)); _serviceScope = serviceScope ?? throw new ArgumentNullException(nameof(serviceScope)); _serviceScope.HandleLifetime(); }
public void ContextDataArePassedOn() { // arrange var schema = Schema.Create( "type Query { foo: String }", c => c.Use(next => context => Task.CompletedTask)); DocumentNode query = Utf8GraphQLParser.Parse("{ foo }"); var errorHandler = new Mock <IErrorHandler>(); var services = new Mock <IServiceProvider>(); services.Setup(t => t.GetService(typeof(IErrorHandler))) .Returns(errorHandler.Object); IRequestServiceScope serviceScope = services.Object.CreateRequestServiceScope(); var variables = new Mock <IVariableValueCollection>(); var operation = new Mock <IOperation>(); operation.Setup(t => t.Document).Returns(query); operation.Setup(t => t.Variables).Returns(variables.Object); var contextData = new Dictionary <string, object> { { "abc", "123" } }; var requestContext = new Mock <IRequestContext>(); requestContext.Setup(t => t.ContextData).Returns(contextData); requestContext.Setup(t => t.ServiceScope).Returns(serviceScope); // act var executionContext = new ExecutionContext( schema, operation.Object, requestContext.Object, CancellationToken.None); // assert Assert.True(ReferenceEquals( contextData, executionContext.ContextData)); }
public void CloneExecutionContext() { // arrange var schema = Schema.Create( "type Query { foo: String }", c => c.Use(next => context => Task.CompletedTask)); var query = Parser.Default.Parse("{ foo }"); var errorHandler = new Mock <IErrorHandler>(); var services = new Mock <IServiceProvider>(); services.Setup(t => t.GetService(typeof(IErrorHandler))) .Returns(errorHandler.Object); IRequestServiceScope serviceScope = services.Object .CreateRequestServiceScope(); var operation = new Mock <IOperation>(); operation.Setup(t => t.Query).Returns(query); var variables = new Mock <IVariableCollection>(); var directives = new DirectiveLookup(new Dictionary <ObjectType, IDictionary <FieldNode, IReadOnlyCollection <IDirective> > >()); var contextData = new Dictionary <string, object> { { "abc", "123" } }; // act var executionContext = new ExecutionContext( schema, serviceScope, operation.Object, variables.Object, directives, contextData, CancellationToken.None); IExecutionContext cloned = executionContext.Clone(); // assert Assert.Equal(contextData, executionContext.ContextData); Assert.Equal(contextData, cloned.ContextData); Assert.False(object.ReferenceEquals( executionContext.Result, cloned.Result)); Assert.False(object.ReferenceEquals( executionContext.ContextData, cloned.ContextData)); }
public QueryContext( ISchema schema, IRequestServiceScope serviceScope, IReadOnlyQueryRequest request) { Schema = schema ?? throw new ArgumentNullException(nameof(schema)); Request = request ?? throw new ArgumentNullException(nameof(request)); ServiceScope = serviceScope ?? throw new ArgumentNullException(nameof(serviceScope)); ContextData = request.Properties == null ? new ConcurrentDictionary <string, object>() : new ConcurrentDictionary <string, object>(request.Properties); }
public RequestContext( IRequestServiceScope serviceScope, Func <ObjectField, FieldNode, FieldDelegate> middlewareFactory, ICachedQuery cachedQuery, IDictionary <string, object> contextData, QueryExecutionDiagnostics diagnostics) { ServiceScope = serviceScope ?? throw new ArgumentNullException(nameof(serviceScope)); _factory = middlewareFactory ?? throw new ArgumentNullException(nameof(middlewareFactory)); CachedQuery = cachedQuery ?? throw new ArgumentNullException(nameof(cachedQuery)); ContextData = contextData ?? throw new ArgumentNullException(nameof(contextData)); Diagnostics = diagnostics ?? throw new ArgumentNullException(nameof(diagnostics)); }
public Task <IExecutionResult> ExecuteAsync( QueryRequest request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } IRequestServiceScope serviceScope = CreateServiceScope( request.Services); var context = new QueryContext( Schema, serviceScope, request.ToReadOnly()); return(ExecuteMiddlewareAsync(context)); }
public QueryContext( ISchema schema, IRequestServiceScope serviceScope, IReadOnlyQueryRequest request, Func <FieldSelection, FieldDelegate> middlewareResolver) { Schema = schema ?? throw new ArgumentNullException(nameof(schema)); Request = request ?? throw new ArgumentNullException(nameof(request)); ServiceScope = serviceScope ?? throw new ArgumentNullException(nameof(serviceScope)); MiddlewareResolver = middlewareResolver ?? throw new ArgumentNullException(nameof(middlewareResolver)); ContextData = request.Properties == null ? new ConcurrentDictionary <string, object>() : new ConcurrentDictionary <string, object>(request.Properties); }
public Task <IExecutionResult> ExecuteAsync( IReadOnlyQueryRequest request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } IRequestServiceScope serviceScope = CreateServiceScope(request.Services); var context = new QueryContext( Schema, serviceScope, request, (field, selection) => _fieldMiddlewareCompiler.GetMiddleware(field), cancellationToken); return(ExecuteMiddlewareAsync(context)); }
public ExecutionContext( ISchema schema, IRequestServiceScope serviceScope, IOperation operation, IVariableCollection variables, DirectiveLookup directives, IDictionary <string, object> contextData, CancellationToken requestAborted) { Schema = schema ?? throw new ArgumentNullException(nameof(schema)); ServiceScope = serviceScope ?? throw new ArgumentNullException(nameof(serviceScope)); Operation = operation ?? throw new ArgumentNullException(nameof(operation)); Variables = variables ?? throw new ArgumentNullException(nameof(variables)); Directives = directives ?? throw new ArgumentNullException(nameof(directives)); ContextData = contextData ?? throw new ArgumentNullException(nameof(contextData)); RequestAborted = requestAborted; ErrorHandler = serviceScope.ServiceProvider .GetRequiredService <IErrorHandler>(); Result = new QueryResult(); FieldHelper = CreateFieldHelper( variables, new FragmentCollection(schema, operation.Query), directives, Result.Errors); Activator = new Activator(serviceScope.ServiceProvider); }