Skip to content

Commit 299929f

Browse files
glen-84michaelstaib
authored andcommitted
Updated ISelection.AsSelector to correctly handle the nodes field (#8122)
1 parent d489aa3 commit 299929f

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/HotChocolate/Core/src/Execution.Projections/Extensions/HotChocolateExecutionSelectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static Expression<Func<TValue, TValue>> AsSelector<TValue>(
7474
}
7575

7676
if ((flags & FieldFlags.GlobalIdNodeField) == FieldFlags.GlobalIdNodeField
77-
|| (flags & FieldFlags.GlobalIdNodeField) == FieldFlags.GlobalIdNodeField)
77+
|| (flags & FieldFlags.GlobalIdNodesField) == FieldFlags.GlobalIdNodesField)
7878
{
7979
return GetOrCreateNodeExpression<TValue>(selection);
8080
}

src/HotChocolate/Core/test/Types.Tests/Types/Relay/NodeResolverTests.cs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma warning disable RCS1102 // Make class static
22
using HotChocolate.Execution;
3+
using HotChocolate.Execution.Processing;
34
using HotChocolate.Language;
45
using HotChocolate.Tests;
56
using HotChocolate.Types.Relay;
@@ -271,6 +272,33 @@ public async Task NodeAttribute_On_Extension_With_Renamed_Id()
271272
.MatchSnapshotAsync();
272273
}
273274

275+
[Fact]
276+
public async Task NodeResolver_And_AsSelector()
277+
{
278+
// arrange
279+
var executor =
280+
await new ServiceCollection()
281+
.AddGraphQLServer()
282+
.AddGlobalObjectIdentification()
283+
.AddTypeExtension<EntityExtension5>()
284+
.AddTypeExtension<Entity2Extension1>()
285+
.AddQueryType<Query>()
286+
.BuildRequestExecutorAsync();
287+
288+
// act
289+
var result = await executor.ExecuteAsync(
290+
"""
291+
{
292+
nodes(ids: ["RW50aXR5OmZvbw=="]) {
293+
id
294+
}
295+
}
296+
""");
297+
298+
// assert
299+
Assert.Null(result.ExpectOperationResult().Errors);
300+
}
301+
274302
public class Query
275303
{
276304
public Entity GetEntity(string name) => new Entity { Name = name, };
@@ -292,7 +320,12 @@ protected override void Configure(
292320

293321
public class Entity
294322
{
295-
public string Id => Name;
323+
public string Id
324+
{
325+
get => Name;
326+
set => Name = value;
327+
}
328+
296329
public string Name { get; set; }
297330
}
298331

@@ -351,6 +384,32 @@ public class EntityExtension4
351384
public static Entity GetEntity(string id) => new() { Name = id, };
352385
}
353386

387+
[Node]
388+
[ExtendObjectType(typeof(Entity))]
389+
public class EntityExtension5
390+
{
391+
[NodeResolver]
392+
public static Entity GetEntity(string id, ISelection selection)
393+
{
394+
selection.AsSelector<Entity>();
395+
396+
return new Entity { Name = id, };
397+
}
398+
}
399+
400+
[Node]
401+
[ExtendObjectType(typeof(Entity2))]
402+
public class Entity2Extension1
403+
{
404+
[NodeResolver]
405+
public static Entity2 GetEntity2(string id, ISelection selection)
406+
{
407+
selection.AsSelector<Entity2>();
408+
409+
return new Entity2 { Name = id, };
410+
}
411+
}
412+
354413
public class QueryEntityRenamed
355414
{
356415
public EntityNoId GetEntity(int id)

0 commit comments

Comments
 (0)