Skip to content

Commit a9a68b4

Browse files
WIP
1 parent 1c35c8b commit a9a68b4

File tree

2 files changed

+202
-2
lines changed

2 files changed

+202
-2
lines changed

src/HotChocolate/Fusion/test/Core.Tests/DemoIntegrationTests.cs

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,83 @@ public class DemoIntegrationTests(ITestOutputHelper output)
1616
{
1717
private readonly Func<ICompositionLog> _logFactory = () => new TestCompositionLog(output);
1818

19+
[Fact]
20+
public async Task Same_Selection_On_Two_Object_Types_That_Require_Data_From_Another_Subgraph()
21+
{
22+
// arrange
23+
var subgraphA = await TestSubgraph.CreateAsync(
24+
"""
25+
type Query {
26+
item1: Item1!
27+
item2: Item2!
28+
}
29+
30+
type Item1 {
31+
product: Product!
32+
}
33+
34+
type Item2 {
35+
product: Product!
36+
}
37+
38+
type Product implements Node {
39+
id: ID!
40+
}
41+
42+
interface Node {
43+
id: ID!
44+
}
45+
""");
46+
47+
var subgraphB = await TestSubgraph.CreateAsync(
48+
"""
49+
type Query {
50+
node(id: ID!): Node
51+
nodes(ids: [ID!]!): [Node]!
52+
}
53+
54+
type Product implements Node {
55+
id: ID!
56+
name: String!
57+
}
58+
59+
interface Node {
60+
id: ID!
61+
}
62+
""");
63+
64+
using var subgraphs = new TestSubgraphCollection(output, [subgraphA, subgraphB]);
65+
var executor = await subgraphs.GetExecutorAsync();
66+
var request = Parse("""
67+
query {
68+
item1 {
69+
product {
70+
id
71+
name
72+
}
73+
}
74+
item2 {
75+
product {
76+
id
77+
name
78+
}
79+
}
80+
}
81+
""");
82+
83+
// act
84+
var result = await executor.ExecuteAsync(
85+
OperationRequestBuilder
86+
.New()
87+
.SetDocument(request)
88+
.Build());
89+
90+
// assert
91+
var snapshot = new Snapshot();
92+
CollectSnapshotData(snapshot, request, result);
93+
await snapshot.MatchMarkdownAsync();
94+
}
95+
1996
[Fact]
2097
public async Task Same_Selection_On_Two_List_Fields_That_Require_Data_From_Another_Subgraph()
2198
{
@@ -29,8 +106,6 @@ interface Node {
29106
type Query {
30107
productsA: [Product]
31108
productsB: [Product]
32-
node(id: ID!): Node
33-
nodes(ids: [ID!]!): [Node]!
34109
}
35110
36111
type Product implements Node {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Same_Selection_On_Two_Object_Types_That_Require_Data_From_Another_Subgraph
2+
3+
## Result
4+
5+
```json
6+
{
7+
"data": {
8+
"item1": {
9+
"product": {
10+
"id": "2",
11+
"name": "string"
12+
}
13+
},
14+
"item2": {
15+
"product": {
16+
"id": "1",
17+
"name": "string"
18+
}
19+
}
20+
}
21+
}
22+
```
23+
24+
## Request
25+
26+
```graphql
27+
{
28+
item1 {
29+
product {
30+
id
31+
name
32+
}
33+
}
34+
item2 {
35+
product {
36+
id
37+
name
38+
}
39+
}
40+
}
41+
```
42+
43+
## QueryPlan Hash
44+
45+
```text
46+
E78C88B24F708E43B14A881AD2A993668E068FE2
47+
```
48+
49+
## QueryPlan
50+
51+
```json
52+
{
53+
"document": "{ item1 { product { id name } } item2 { product { id name } } }",
54+
"rootNode": {
55+
"type": "Sequence",
56+
"nodes": [
57+
{
58+
"type": "Resolve",
59+
"subgraph": "Subgraph_1",
60+
"document": "query fetch_item1_item2_1 { item1 { product { id __fusion_exports__1: id } } item2 { product { id __fusion_exports__2: id } } }",
61+
"selectionSetId": 0,
62+
"provides": [
63+
{
64+
"variable": "__fusion_exports__1"
65+
},
66+
{
67+
"variable": "__fusion_exports__2"
68+
}
69+
]
70+
},
71+
{
72+
"type": "Compose",
73+
"selectionSetIds": [
74+
0
75+
]
76+
},
77+
{
78+
"type": "Parallel",
79+
"nodes": [
80+
{
81+
"type": "Resolve",
82+
"subgraph": "Subgraph_2",
83+
"document": "query fetch_item1_item2_2($__fusion_exports__1: ID!) { node(id: $__fusion_exports__1) { ... on Product { name } } }",
84+
"selectionSetId": 3,
85+
"path": [
86+
"node"
87+
],
88+
"requires": [
89+
{
90+
"variable": "__fusion_exports__1"
91+
}
92+
]
93+
},
94+
{
95+
"type": "Resolve",
96+
"subgraph": "Subgraph_2",
97+
"document": "query fetch_item1_item2_3($__fusion_exports__2: ID!) { node(id: $__fusion_exports__2) { ... on Product { name } } }",
98+
"selectionSetId": 4,
99+
"path": [
100+
"node"
101+
],
102+
"requires": [
103+
{
104+
"variable": "__fusion_exports__2"
105+
}
106+
]
107+
}
108+
]
109+
},
110+
{
111+
"type": "Compose",
112+
"selectionSetIds": [
113+
3,
114+
4
115+
]
116+
}
117+
]
118+
},
119+
"state": {
120+
"__fusion_exports__1": "Product_id",
121+
"__fusion_exports__2": "Product_id"
122+
}
123+
}
124+
```
125+

0 commit comments

Comments
 (0)