diff --git a/src/HotChocolate/Core/src/Types/Execution/Processing/OperationCompiler.CoerceArgumentValues.cs b/src/HotChocolate/Core/src/Types/Execution/Processing/OperationCompiler.CoerceArgumentValues.cs index f10ae9343a6..0f67805b562 100644 --- a/src/HotChocolate/Core/src/Types/Execution/Processing/OperationCompiler.CoerceArgumentValues.cs +++ b/src/HotChocolate/Core/src/Types/Execution/Processing/OperationCompiler.CoerceArgumentValues.cs @@ -74,7 +74,7 @@ private ArgumentValue CreateArgumentValue( _inputValueParser.ParseLiteral(value, argument), value); } - catch (LeafCoercionException ex) + catch (GraphQLException ex) { return new ArgumentValue(argument, ex.Errors[0]); } diff --git a/src/HotChocolate/Core/test/Types.Tests/Types/Relay/Issue7346Tests.cs b/src/HotChocolate/Core/test/Types.Tests/Types/Relay/Issue7346Tests.cs new file mode 100644 index 00000000000..75239002952 --- /dev/null +++ b/src/HotChocolate/Core/test/Types.Tests/Types/Relay/Issue7346Tests.cs @@ -0,0 +1,78 @@ +using HotChocolate.Execution; +using Microsoft.Extensions.DependencyInjection; + +namespace HotChocolate.Types.Relay; + +public class Issue7346Tests +{ + [Fact] + public async Task Invalid_Id_Does_Not_Erase_Sibling_Data() + { + var result = + await new ServiceCollection() + .AddGraphQLServer() + .AddQueryType() + .AddGlobalObjectIdentification(false) + .ExecuteRequestAsync( + """ + { + byId(id: "invalid") + unrelated + } + """); + + result.ToJson().MatchInlineSnapshot( + """ + { + "errors": [ + { + "message": "The node ID string has an invalid format.", + "path": [ + "byId" + ], + "extensions": { + "originalValue": "invalid" + } + } + ], + "data": { + "byId": null, + "unrelated": "value" + } + } + """); + } + + [Fact] + public async Task Invalid_Id_On_Skipped_Field_Does_Not_Error() + { + var result = + await new ServiceCollection() + .AddGraphQLServer() + .AddQueryType() + .AddGlobalObjectIdentification(false) + .ExecuteRequestAsync( + """ + { + byId(id: "invalid") @skip(if: true) + unrelated + } + """); + + result.ToJson().MatchInlineSnapshot( + """ + { + "data": { + "unrelated": "value" + } + } + """); + } + + public class ProbeQuery + { + public int? GetById([ID] int id) => id; + + public string GetUnrelated() => "value"; + } +}