Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showcase invalid ID producing top-level error and erasing rest of response #7345

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text;
using HotChocolate.Configuration;
using HotChocolate.Execution;
using HotChocolate.Resolvers;
using HotChocolate.Types.Descriptors;
using HotChocolate.Types.Descriptors.Definitions;
using HotChocolate.Utilities;
Expand Down Expand Up @@ -462,6 +463,81 @@ public async Task EnsureIdIsOnlyAppliedOnce()
Assert.Equal(1, inspector.Count);
}

[Fact]
public async Task InvalidId_ShouldNotEraseRestOfResponse()
{
var result =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<InvalidIdQuery>()
.AddGlobalObjectIdentification(false)
.ExecuteRequestAsync("""
{
byId(id: "invalid")
unrelated
}
""");

CookieCrumble.SnapshotExtensions
.MatchInlineSnapshot(result, """
{
"errors": [
{
"message": "The node ID string has an invalid format.",
"locations": [
{
"line": 2,
"column": 8
}
],
"path": [
"byId"
],
"extensions": {
"originalValue": "invalid"
}
}
],
"data": {
"byId": null,
"unrelated": "value"
}
}
""");
}

[Fact]
public async Task InvalidId_ShouldNotEraseRestOfResponse_IfSkipped()
{
var result =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<InvalidIdQuery>()
.AddGlobalObjectIdentification(false)
.ExecuteRequestAsync("""
{
byId(id: "invalid") @skip(if: true)
unrelated
}
""");

CookieCrumble.SnapshotExtensions
.MatchInlineSnapshot(result, """
{
"data": {
"unrelated": "value"
}
}
""");
}

public class InvalidIdQuery
{
public int? GetById([ID] int id, IResolverContext context) => id;

public string Unrelated() => "value";
}

[SuppressMessage("Performance", "CA1822:Mark members as static")]
public class Query
{
Expand Down
Loading