ScopedDataContext is lost when querying `nodes` for global object identification
ChauThan opened this issue · 0 comments
ChauThan commented
Product
Hot Chocolate
Version
14.0.0
Link to minimal reproduction
https://github.com/ChauThan/bug-report/tree/main/hotchocolate/globalobjectidentification
Steps to reproduce
- Run reproduction.
- Execute query
node
to getAdditionalData
{
node(id: "QXV0aG9yOjE=") {
id
... on Author {
AdditionalData
}
}
}
Data returns correctly.
{
"data": {
"node": {
"id": "QXV0aG9yOjE=",
"AdditionalData": "This is the additional data of Author 1"
}
}
}
- Execute query
nodes
with same id to getAdditionalData
query {
nodes(ids: ["QXV0aG9yOjE="]) {
id
... on Author {
AdditionalData
id
name
}
}
}
{
"data": {
"nodes": [
{
"id": "QXV0aG9yOjE=",
"AdditionalData": "Data not found.",
"name": "Author 1"
}
]
}
}
What is expected?
Data of nodes
returns same as node
What is actually happening?
I am using ScopeContextData to resolve this field..
public class AuthorType : ObjectType<Author>
{
protected override void Configure(IObjectTypeDescriptor<Author> descriptor)
{
descriptor.ImplementsNode()
.IdField(s => s.Id)
.ResolveNode((ctx, id) =>
{
var author = ctx.Services.GetRequiredService<AuthorRepository>().GetAuthorById(id);
ctx.SetScopedState("AdditionalData", "This is the additional data of " + author?.Name);
return Task.FromResult(author);
});
descriptor.Field("AdditionalData")
.Type<StringType>()
.Resolve<string>(ctx => ctx.ScopedContextData.TryGetValue("AdditionalData", out var scopedContextData)
? scopedContextData.ToString()
: "Data not found.");
}
}
It appears all ScopedContextData
is cleared in nodes
Relevant log output
No response
Additional context
No response