private object?DeserializeLeaf( object resultValue, ILeafType type, Path path, IInputField?field) { if (resultValue is IValueNode node) { return(ParseLeaf(node, type, path, field)); } try { return(type.Deserialize(resultValue)); } catch (SerializationException ex) { if (field is null) { throw new SerializationException(ex.Errors[0].WithPath(path), ex.Type, path); } IError error = ErrorBuilder.FromError(ex.Errors[0]) .SetPath(path) .SetExtension(nameof(field), field.Coordinate.ToString()) .SetExtension("fieldType", type.Name.Value) .Build(); throw new SerializationException(error, ex.Type, path); } }
private static void ReportErrors( NameString schemaName, IResolverContext context, IEnumerable <IError> errors) { foreach (IError error in errors) { IErrorBuilder builder = ErrorBuilder.FromError(error) .SetExtension(_remoteErrorField, error.RemoveException()) .SetExtension(_schemaNameErrorField, schemaName.Value); if (error.Path != null) { Path path = RewriteErrorPath(error, context.Path); builder.SetPath(path) .ClearLocations() .AddLocation(context.FieldSelection); } else if (IsHttpError(error)) { builder.SetPath(context.Path) .ClearLocations() .AddLocation(context.FieldSelection); } context.ReportError(builder.Build()); } }
public static IError ArgumentDefaultValueIsInvalid( string responseName, GraphQLException exception) { return(ErrorBuilder.FromError(exception.Errors[0]) .SetExtension("responseName", responseName) .Build()); }
public static IError ArgumentValueIsInvalid( ArgumentNode argument, string responseName, GraphQLException exception) { return(ErrorBuilder.FromError(exception.Errors[0]) .AddLocation(argument) .SetExtension("responseName", responseName) .Build()); }
public static IError InvalidLeafValue( GraphQLException exception, FieldNode field, Path path) { return(ErrorBuilder.FromError(exception.Errors[0]) .AddLocation(field) .SetPath(path) .SetCode(ErrorCodes.Execution.CannotSerializeLeafValue) .Build()); }
public IError OnError(IError error) { if (error.Exception is DuplicateKeyException ex) { return(ErrorBuilder.FromError(error) .SetMessage(ex.Message) .SetException(null) .SetCode(ErrorCodes.DuplicateKey) .Build()); } return(error); }
public IError OnError(IError error) { if (error.Exception is EntityDoesNotExistException ex) { return(ErrorBuilder.FromError(error) .SetMessage(ex.Message) .SetException(null) .SetCode(ErrorCodes.EntityDoesNotExist) .SetExtension("ID", ex.Id) .SetExtension("Type", ex.Type) .RemoveExtension("stackTrace") .Build()); } return(error); }
public IError OnError(IError error) { if (error.Exception is ValidationException vx) { var childErrors = vx.Errors.Select(x => new FluentValidationProblemDetail(x)) .Select( x => new Error(x.ErrorMessage) .WithCode(x.ErrorCode) .SetExtension("severity", x.Severity.ToString()) .SetExtension("attemptedValue", x.AttemptedValue) .SetExtension("field", x.PropertyName) .SetExtension("propertyName", x.PropertyName) ); var result = new AggregateError(childErrors); return(result); } if (error.Exception is IProblemDetailsData ex) { var builder = ErrorBuilder.FromError(error); builder .SetException(error.Exception) .SetMessage(error.Exception.Message) .WithProblemDetails(ex); if (error.Exception is NotFoundException) { builder.SetCode("NOTFOUND"); } if (error.Exception is NotAuthorizedException) { builder.SetCode("NOTAUTHORIZED"); } if (error.Exception is RequestFailedException) { builder.SetCode("FAILED"); } return(builder.Build()); } return(error); }
private static void ReportErrors( IResolverContext context, IEnumerable <IError> errors) { foreach (IError error in errors) { IErrorBuilder builder = ErrorBuilder.FromError(error) .SetExtension("remote", error); if (error.Path != null) { Path path = RewriteErrorPath(error, context.Path); builder.SetPath(path) .ClearLocations() .AddLocation(context.FieldSelection); } context.ReportError(builder.Build()); } }
public async Task ConnectionLost() { // arrange var connections = new Dictionary <string, HttpClient>(); IHttpClientFactory clientFactory = CreateRemoteSchemas(connections); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(clientFactory); serviceCollection.AddStitchedSchema(builder => builder.AddSchemaFromHttp("contract") .AddSchemaFromHttp("customer") .RenameType("CreateCustomerInput", "CreateCustomerInput2") .AddExtensionsFromString( FileResource.Open("StitchingExtensions.graphql")) .AddSchemaConfiguration(c => c.RegisterType <PaginationAmountType>()) .AddExecutionConfiguration(b => { b.AddErrorFilter(error => { if (error.Exception is Exception ex) { return(ErrorBuilder.FromError(error) .ClearExtensions() .SetMessage(ex.GetType().FullName) .SetException(null) .Build()); } ; return(error); }); })); IServiceProvider services = serviceCollection.BuildServiceProvider(); IQueryExecutor executor = services .GetRequiredService <IQueryExecutor>(); IExecutionResult result = null; using (IServiceScope scope = services.CreateScope()) { IReadOnlyQueryRequest request = QueryRequestBuilder.New() .SetQuery(@" mutation { createCustomer(input: { name: ""a"" }) { customer { name contracts { id } } } }") .SetServices(scope.ServiceProvider) .Create(); result = await executor.ExecuteAsync(request); } var client = new HttpClient { BaseAddress = new Uri("http://127.0.0.1") };; connections["contract"] = client; connections["customer"] = client; // act using (IServiceScope scope = services.CreateScope()) { IReadOnlyQueryRequest request = QueryRequestBuilder.New() .SetQuery(@" mutation { createCustomer(input: { name: ""a"" }) { customer { name contracts { id } } } }") .SetServices(scope.ServiceProvider) .Create(); result = await executor.ExecuteAsync(request); } // assert result.MatchSnapshot(); }