internal async Task <ExecutionResult> Execute( object rootObject, string query, string operationName, Inputs inputs, IUserContext userContext, 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 = userContext, ValidationRules = rules, CancellationToken = cancellationToken, }; if (userContext is IDataLoaderContextProvider) { configuration.Listeners.Add(new DataLoaderListener()); } if (enableProfiling) { configuration.FieldMiddleware.Use <InstrumentFieldsMiddleware>(); } 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); error.SetCode(exception.InnerException ?? 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); }
public ExecutionErrors Transform(ExecutionErrors errors) => errors.Aggregate(new ExecutionErrors(), (result, executionError) => { var exception = new FieldResolutionException(executionError); var error = new ExecutionError(exception.Message, exception); foreach (var location in executionError.Locations ?? Enumerable.Empty <ErrorLocation>()) { error.AddLocation(location.Line, location.Column); } error.Path = executionError.Path; result.Add(error); return(result); });
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 = executionError.Path; errors.Add(error); } result.Errors = errors; } return(result); }