コード例 #1
0
        public void Can_Create_Wrapper_With_DataLoaderContextProvider_Support()
        {
            var wrapper = UserContextWrapper.Create(new UserContextWithDataLoaderContextProvider(), new DependencyInjector());

            Assert.IsNotNull(wrapper);
            Assert.IsInstanceOfType(wrapper, typeof(IDataLoaderContextProvider));
        }
コード例 #2
0
        public void Can_Create_Wrapper_Without_DataLoaderContextProvider_Support()
        {
            var wrapper = UserContextWrapper.Create(new UserContext(), new DependencyInjector());

            Assert.IsNotNull(wrapper);
            Assert.IsFalse(wrapper is IDataLoaderContextProvider);
        }
コード例 #3
0
                public async Task <ExecutionResult> ExecuteAsync(ExecutionContext context)
                {
                    var outerUserContextWrapper = context.UserContext;
                    var userContext             = (context.UserContext as IUserContextAccessor)?.UserContext;

                    try
                    {
                        context.UserContext = UserContextWrapper.Create(userContext, _injector);
                        return(await _innerStrategy.ExecuteAsync(context));
                    }
                    finally
                    {
                        context.UserContext = outerUserContextWrapper;
                    }
                }
コード例 #4
0
        internal async Task <ExecutionResult> Execute(
            object rootObject,
            string query,
            string operationName,
            Inputs inputs,
            IUserContext userContext,
            IDependencyInjector dependencyInjector,
            ComplexityConfiguration complexityConfiguration,
            bool enableValidation = true,
            bool enableProfiling  = false,
            IEnumerable <IValidationRule> rules = null,
            CancellationToken cancellationToken = default,
            IEnumerable <IDocumentExecutionListener> listeners = null)
        {
            if (!enableValidation)
            {
                rules = new[] { new NoopValidationRule() };
            }
            var configuration = new ExecutionOptions
            {
                Schema                  = _schema,
                Root                    = rootObject,
                Query                   = query,
                OperationName           = operationName,
                Inputs                  = inputs,
                UserContext             = UserContextWrapper.Create(userContext, dependencyInjector ?? new WrappedDependencyInjector(_constructor.TypeResolutionDelegate)),
                ValidationRules         = rules != null && rules.Any() ? rules : null,
                ComplexityConfiguration = complexityConfiguration,
                CancellationToken       = cancellationToken,
                ExposeExceptions        = _exposeExceptions
            };

            if (listeners != null && listeners.Any())
            {
                foreach (var listener in listeners)
                {
                    configuration.Listeners.Add(listener);
                }
            }

            if (userContext is IDataLoaderContextProvider)
            {
                configuration.Listeners.Add(new DataLoaderListener());
            }

            if (enableProfiling)
            {
                configuration.FieldMiddleware.Use <InstrumentFieldsMiddleware>();
            }

            foreach (var middleware in _middleware)
            {
                configuration.FieldMiddleware.Use(middleware);
            }

            var result = await _documentExecutor.ExecuteAsync(configuration).ConfigureAwait(false);

            if (result.Errors != null && _errorTransformation != null)
            {
                result.Errors = _errorTransformation.Transform(result.Errors);
            }

            return(result);
        }
コード例 #5
0
        public void Should_Forward_DataLoaderContextProvider_FetchData_Call()
        {
            var wrapper = UserContextWrapper.Create(new UserContextWithDataLoaderContextProvider(), new DependencyInjector());

            Assert.ThrowsException <FetchDataCalledException>(() => (wrapper as IDataLoaderContextProvider).FetchData(CancellationToken.None));
        }
コード例 #6
0
        internal async Task <ExecutionResult> Execute(
            object rootObject,
            string query,
            string operationName,
            Inputs inputs,
            IUserContext userContext,
            IDependencyInjector dependencyInjector,
            ComplexityConfiguration complexityConfiguration,
            bool enableValidation = true,
            bool enableProfiling  = false,
            IEnumerable <IValidationRule> rules = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!enableValidation)
            {
                rules = new[] { new NoopValidationRule() };
            }
            var configuration = new ExecutionOptions
            {
                Schema                  = _schema,
                Root                    = rootObject,
                Query                   = query,
                OperationName           = operationName,
                Inputs                  = inputs,
                UserContext             = UserContextWrapper.Create(userContext, dependencyInjector ?? new WrappedDependencyInjector(_constructor.TypeResolutionDelegate)),
                ValidationRules         = rules != null && rules.Any() ? rules : null,
                ComplexityConfiguration = complexityConfiguration,
                CancellationToken       = cancellationToken,
            };

            if (userContext is IDataLoaderContextProvider)
            {
                configuration.Listeners.Add(new DataLoaderListener());
            }

            if (enableProfiling)
            {
                configuration.FieldMiddleware.Use <InstrumentFieldsMiddleware>();
            }

            foreach (var middleware in _middleware)
            {
                configuration.FieldMiddleware.Use(middleware);
            }

            var result = await _documentExecutor.ExecuteAsync(configuration).ConfigureAwait(false);

            if (result.Errors != null)
            {
                var errors = new ExecutionErrors();
                foreach (var executionError in result.Errors)
                {
                    var exception = new FieldResolutionException(executionError);
                    var error     = new ExecutionError(exception.Message, exception);
                    foreach (var location in executionError.Locations ?? new ErrorLocation[0])
                    {
                        error.AddLocation(location.Line, location.Column);
                    }
                    error.Path.AddRange(executionError.Path);
                    errors.Add(error);
                }
                result.Errors = errors;
            }

            return(result);
        }