Skip to content

Commit 87bf696

Browse files
committed
Fix projection of fragment spreads in connection node fields (items/edges/node)
1 parent c40e9ba commit 87bf696

7 files changed

Lines changed: 344 additions & 1 deletion

src/GraphQL.EntityFramework/IncludeAppender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ void ProcessConnectionNodeFields(
441441
return;
442442
}
443443

444-
foreach (var selection in selectionSet.Selections.OfType<GraphQLField>())
444+
foreach (var selection in EnumerateFields(selectionSet, context))
445445
{
446446
var fieldName = selection.Name.StringValue;
447447
if (IsConnectionNodeName(fieldName))
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
target: {
3+
Data: {
4+
parentEntitiesConnection: {
5+
totalCount: 8,
6+
edges: [
7+
{
8+
cursor: 1,
9+
node: {
10+
property: Value1
11+
}
12+
},
13+
{
14+
cursor: 2,
15+
node: {
16+
property: Value2
17+
}
18+
}
19+
]
20+
}
21+
}
22+
},
23+
sql: [
24+
{
25+
Text:
26+
select COUNT(*)
27+
from ParentEntities as p
28+
},
29+
{
30+
Text:
31+
select p.Id,
32+
p.Property
33+
from ParentEntities as p
34+
order by p.Property
35+
offset @p rows fetch next @p1 rows only,
36+
Parameters: {
37+
@p: 1,
38+
@p1: 2
39+
}
40+
}
41+
]
42+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
target: {
3+
Data: {
4+
parentEntitiesConnection: {
5+
totalCount: 8,
6+
items: [
7+
{
8+
property: Value1
9+
},
10+
{
11+
property: Value2
12+
}
13+
]
14+
}
15+
}
16+
},
17+
sql: [
18+
{
19+
Text:
20+
select COUNT(*)
21+
from ParentEntities as p
22+
},
23+
{
24+
Text:
25+
select p.Id,
26+
p.Property
27+
from ParentEntities as p
28+
order by p.Property
29+
offset @p rows fetch next @p1 rows only,
30+
Parameters: {
31+
@p: 1,
32+
@p1: 2
33+
}
34+
}
35+
]
36+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
target: {
3+
Data: {
4+
parentEntitiesConnection: {
5+
totalCount: 2,
6+
items: [
7+
{
8+
property: Value4,
9+
children: [
10+
{
11+
property: Value5
12+
}
13+
]
14+
}
15+
]
16+
}
17+
}
18+
},
19+
sql: [
20+
{
21+
Text:
22+
select COUNT(*)
23+
from ParentEntities as p
24+
},
25+
{
26+
Text:
27+
select p0.Id,
28+
p0.Property,
29+
c.Id,
30+
c.ParentId,
31+
c.Property
32+
from (select p.Id,
33+
p.Property
34+
from ParentEntities as p
35+
order by p.Property
36+
offset @p rows fetch next @p1 rows only) as p0
37+
left outer join
38+
ChildEntities as c
39+
on p0.Id = c.ParentId
40+
order by p0.Property,
41+
p0.Id,
42+
c.Id,
43+
Parameters: {
44+
@p: 1,
45+
@p1: 2
46+
}
47+
}
48+
]
49+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
target: {
3+
Data: {
4+
parentEntitiesConnection: {
5+
totalCount: 8,
6+
items: [
7+
{
8+
property: Value1
9+
},
10+
{
11+
property: Value2
12+
}
13+
]
14+
}
15+
}
16+
},
17+
sql: [
18+
{
19+
Text:
20+
select COUNT(*)
21+
from ParentEntities as p
22+
},
23+
{
24+
Text:
25+
select p.Id,
26+
p.Property
27+
from ParentEntities as p
28+
order by p.Property
29+
offset @p rows fetch next @p1 rows only,
30+
Parameters: {
31+
@p: 1,
32+
@p1: 2
33+
}
34+
}
35+
]
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
target: {
3+
Data: {
4+
parentEntitiesConnection: {
5+
totalCount: 8,
6+
items: [
7+
{
8+
property: Value1
9+
},
10+
{
11+
property: Value2
12+
}
13+
]
14+
}
15+
}
16+
},
17+
sql: [
18+
{
19+
Text:
20+
select COUNT(*)
21+
from ParentEntities as p
22+
},
23+
{
24+
Text:
25+
select p.Id,
26+
p.Property
27+
from ParentEntities as p
28+
order by p.Property
29+
offset @p rows fetch next @p1 rows only,
30+
Parameters: {
31+
@p: 1,
32+
@p1: 2
33+
}
34+
}
35+
]
36+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
public partial class IntegrationTests
2+
{
3+
[Fact]
4+
public async Task Connection_items_with_inline_fields()
5+
{
6+
var query =
7+
"""
8+
{
9+
parentEntitiesConnection(first:2, after: "0") {
10+
totalCount
11+
items {
12+
property
13+
}
14+
}
15+
}
16+
""";
17+
var entities = BuildEntities(8);
18+
19+
await using var database = await sqlInstance.Build();
20+
await RunQuery(database, query, null, null, false, entities.ToArray());
21+
}
22+
23+
[Fact]
24+
public async Task Connection_items_with_fragment_spread()
25+
{
26+
var query =
27+
"""
28+
{
29+
parentEntitiesConnection(first:2, after: "0") {
30+
totalCount
31+
items {
32+
...parentFields
33+
}
34+
}
35+
}
36+
37+
fragment parentFields on Parent {
38+
property
39+
}
40+
""";
41+
var entities = BuildEntities(8);
42+
43+
await using var database = await sqlInstance.Build();
44+
await RunQuery(database, query, null, null, false, entities.ToArray());
45+
}
46+
47+
[Fact]
48+
public async Task Connection_edges_node_with_fragment_spread()
49+
{
50+
var query =
51+
"""
52+
{
53+
parentEntitiesConnection(first:2, after: "0") {
54+
totalCount
55+
edges {
56+
cursor
57+
node {
58+
...parentFields
59+
}
60+
}
61+
}
62+
}
63+
64+
fragment parentFields on Parent {
65+
property
66+
}
67+
""";
68+
var entities = BuildEntities(8);
69+
70+
await using var database = await sqlInstance.Build();
71+
await RunQuery(database, query, null, null, false, entities.ToArray());
72+
}
73+
74+
[Fact]
75+
public async Task Connection_items_with_inline_fragment()
76+
{
77+
var query =
78+
"""
79+
{
80+
parentEntitiesConnection(first:2, after: "0") {
81+
totalCount
82+
items {
83+
... on Parent {
84+
property
85+
}
86+
}
87+
}
88+
}
89+
""";
90+
var entities = BuildEntities(8);
91+
92+
await using var database = await sqlInstance.Build();
93+
await RunQuery(database, query, null, null, false, entities.ToArray());
94+
}
95+
96+
[Fact]
97+
public async Task Connection_items_with_fragment_spread_and_children()
98+
{
99+
var query =
100+
"""
101+
{
102+
parentEntitiesConnection(first:2, after: "0") {
103+
totalCount
104+
items {
105+
...parentWithChildren
106+
}
107+
}
108+
}
109+
110+
fragment parentWithChildren on Parent {
111+
property
112+
children {
113+
property
114+
}
115+
}
116+
""";
117+
var entity1 = new ParentEntity
118+
{
119+
Property = "Value1"
120+
};
121+
var entity2 = new ChildEntity
122+
{
123+
Property = "Value2"
124+
};
125+
var entity3 = new ChildEntity
126+
{
127+
Property = "Value3"
128+
};
129+
entity1.Children.Add(entity2);
130+
entity1.Children.Add(entity3);
131+
var entity4 = new ParentEntity
132+
{
133+
Property = "Value4"
134+
};
135+
var entity5 = new ChildEntity
136+
{
137+
Property = "Value5"
138+
};
139+
entity4.Children.Add(entity5);
140+
141+
await using var database = await sqlInstance.Build();
142+
await RunQuery(database, query, null, null, false, [entity1, entity2, entity3, entity4, entity5]);
143+
}
144+
}

0 commit comments

Comments
 (0)