Skip to content

Commit f122129

Browse files
authored
Added missing ParallelExecutable flag to node and nodes fields (#7661)
1 parent 58b0888 commit f122129

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/HotChocolate/Core/src/Types/Types/Relay/NodeFieldTypeInterceptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static void CreateNodeField(
9494
};
9595
}),
9696
},
97-
Flags = FieldFlags.GlobalIdNodeField
97+
Flags = FieldFlags.ParallelExecutable | FieldFlags.GlobalIdNodeField
9898
};
9999

100100
// In the projection interceptor we want to change the context data that is on this field
@@ -134,7 +134,7 @@ private static void CreateNodesField(
134134
};
135135
}),
136136
},
137-
Flags = FieldFlags.GlobalIdNodesField
137+
Flags = FieldFlags.ParallelExecutable | FieldFlags.GlobalIdNodesField
138138
};
139139

140140
// In the projection interceptor we want to change the context data that is on this field

src/HotChocolate/Core/test/Execution.Tests/Integration/DataLoader/DataLoaderTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,43 @@ await ExpectValid(
5959
await snapshot.MatchMarkdownAsync();
6060
}
6161

62+
[Fact]
63+
public async Task FetchMultipleNodesDataLoader()
64+
{
65+
var batchFetchCount = 0;
66+
67+
await ExpectValid(
68+
"""
69+
{
70+
a: node(id: "RW50aXR5OjE==") { ... on Entity { id } }
71+
b: node(id: "RW50aXR5OjI==") { ... on Entity { id } }
72+
}
73+
""",
74+
configure: b => b
75+
.AddGraphQL()
76+
.AddGlobalObjectIdentification()
77+
.AddObjectType<Entity>(descriptor =>
78+
{
79+
descriptor
80+
.ImplementsNode()
81+
.IdField(e => e.Id)
82+
.ResolveNode(
83+
async (ctx, id) => await ctx.BatchDataLoader<int, Entity>(
84+
(keys, _) =>
85+
{
86+
batchFetchCount++;
87+
88+
return Task.FromResult<IReadOnlyDictionary<int, Entity>>(
89+
keys.ToDictionary(t => t, _ => new Entity { Id = id }));
90+
})
91+
.LoadAsync(id))
92+
.Resolve(ctx => ctx.Parent<Entity>().Id);
93+
})
94+
.AddQueryType());
95+
96+
Assert.Equal(1, batchFetchCount);
97+
}
98+
6299
[LocalFact]
63100
public async Task FetchDataLoader()
64101
{
@@ -667,4 +704,9 @@ public CounterDataLoader(DataLoaderOptions options) : base(options)
667704
protected override Task<string> LoadSingleAsync(string key, CancellationToken cancellationToken)
668705
=> Task.FromResult(key + Counter);
669706
}
707+
708+
public class Entity
709+
{
710+
public int Id { get; set; }
711+
}
670712
}

0 commit comments

Comments
 (0)