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

14.x regression - Node "id" field can no longer be provided via an extension type #7829

Open
bbarry opened this issue Dec 14, 2024 · 0 comments

Comments

@bbarry
Copy link

bbarry commented Dec 14, 2024

Product

Hot Chocolate

Version

14.2.0

Link to minimal reproduction

https://github.com/ChilliCream/graphql-platform

Steps to reproduce

Reproduction - add to src/HotChocolate/Core/test/Types.Tests/Types/Relay/NodeResolverTests.cs

[Fact]
public async Task NodeAttribute_On_Extension_With_Renamed_Id()
{
	Snapshot.FullName();

	await new ServiceCollection()
		.AddGraphQL()
		.AddQueryType<QueryEntityRenamed>()
		.AddTypeExtension<EntityExtensionRenamingId>()
		.ExecuteRequestAsync(
			"""
			{
				entity(id: 5) {
					id
					data
				}
			}
			""")
		.MatchSnapshotAsync();
}

public class QueryEntityRenamed
{
	public EntityNoId GetEntity(int id) => new EntityNoId { Data = id };
}

public class EntityNoId
{
	public int Data { get; set; }
}

[Node]
[ExtendObjectType(typeof(EntityNoId))]
public class EntityExtensionRenamingId
{
	public int GetId([Parent]EntityNoId entity) => entity.Data;

	[NodeResolver]
	public EntityNoId GetEntity(int id) => new() { Data = id, };
}

version 13.9.14 result:

{
  "data": {
    "entity": {
      "id": "RW50aXR5Tm9JZAppNQ==",
      "data": 5
    }
  }
}

What is expected?

The actual value for the id should have changed due to the new id serializer but the entity should still be returned:

{
  "data": {
    "entity": {
      "id": "RW50aXR5Tm9JZDo1",
      "data": 5
    }
  }
}

What is actually happening?

version 14.2.0 result:

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field.",
      "locations": [
        {
          "line": 3,
          "column": 9
        }
      ],
      "path": [
        "entity",
        "id"
      ],
      "extensions": {
        "code": "HC0018"
      }
    }
  ],
  "data": {
    "entity": null
  }
}

Relevant log output

Additional context

It can be worked around as long as you control the type that will implement the Node interface by adding a read only property Id. Unfortunately if I do not own the type being returned then I cannot find another workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant