Skip to content

Commit 460f874

Browse files
committed
Added more query plan integration tests.
1 parent 1c673c9 commit 460f874

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,52 @@ ... on Patient1 {
930930
snapshot.Add(result.QueryPlan, nameof(result.QueryPlan));
931931
await snapshot.MatchAsync();
932932
}
933+
934+
[Fact]
935+
public async Task Query_Plan_24_Field_Requirement_And_Fields_In_Context()
936+
{
937+
// arrange
938+
using var demoProject = await DemoProject.CreateAsync();
939+
940+
var fusionGraph = await new FusionGraphComposer().ComposeAsync(
941+
new[]
942+
{
943+
demoProject.Reviews2.ToConfiguration(Reviews2ExtensionSdl),
944+
demoProject.Accounts.ToConfiguration(AccountsExtensionSdl),
945+
demoProject.Products.ToConfiguration(ProductsExtensionSdl),
946+
demoProject.Shipping.ToConfiguration(ShippingExtensionSdl),
947+
},
948+
FusionFeatureFlags.NodeField);
949+
950+
// act
951+
var result = await CreateQueryPlanAsync(
952+
fusionGraph,
953+
"""
954+
query Requires {
955+
reviews {
956+
body
957+
author {
958+
name
959+
birthdate
960+
}
961+
product {
962+
id
963+
name
964+
deliveryEstimate(zip: "12345") {
965+
min
966+
max
967+
}
968+
}
969+
}
970+
}
971+
""");
972+
973+
// assert
974+
var snapshot = new Snapshot();
975+
snapshot.Add(result.UserRequest, nameof(result.UserRequest));
976+
snapshot.Add(result.QueryPlan, nameof(result.QueryPlan));
977+
await snapshot.MatchAsync();
978+
}
933979

934980
private static async Task<(DocumentNode UserRequest, QueryPlan QueryPlan)> CreateQueryPlanAsync(
935981
Skimmed.Schema fusionGraph,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
UserRequest
2+
---------------
3+
query Requires {
4+
reviews {
5+
body
6+
author {
7+
name
8+
birthdate
9+
}
10+
product {
11+
id
12+
name
13+
deliveryEstimate(zip: "12345") {
14+
min
15+
max
16+
}
17+
}
18+
}
19+
}
20+
---------------
21+
22+
QueryPlan
23+
---------------
24+
{
25+
"document": "query Requires { reviews { body author { name birthdate } product { id name deliveryEstimate(zip: \u002212345\u0022) { min max } } } }",
26+
"operation": "Requires",
27+
"rootNode": {
28+
"type": "Sequence",
29+
"nodes": [
30+
{
31+
"type": "Resolve",
32+
"subgraph": "Reviews2",
33+
"document": "query Requires_1 { reviews { body author { name __fusion_exports__3: id } product { id __fusion_exports__4: id } } }",
34+
"selectionSetId": 0
35+
},
36+
{
37+
"type": "Compose",
38+
"selectionSetIds": [
39+
0
40+
]
41+
},
42+
{
43+
"type": "Parallel",
44+
"nodes": [
45+
{
46+
"type": "ResolveByKeyBatch",
47+
"subgraph": "Accounts",
48+
"document": "query Requires_2($__fusion_exports__3: [ID!]!) { nodes(ids: $__fusion_exports__3) { ... on User { birthdate __fusion_exports__3: id } } }",
49+
"selectionSetId": 4,
50+
"argumentTypes": [
51+
{
52+
"argument": "__fusion_exports__3",
53+
"type": "[ID!]!"
54+
}
55+
],
56+
"path": [
57+
"nodes"
58+
],
59+
"requires": [
60+
{
61+
"variable": "__fusion_exports__3"
62+
}
63+
]
64+
},
65+
{
66+
"type": "ResolveByKeyBatch",
67+
"subgraph": "Products",
68+
"document": "query Requires_4($__fusion_exports__4: [ID!]!) { nodes(ids: $__fusion_exports__4) { ... on Product { name __fusion_exports__1: dimension { size } __fusion_exports__2: dimension { weight } __fusion_exports__4: id } } }",
69+
"selectionSetId": 2,
70+
"argumentTypes": [
71+
{
72+
"argument": "__fusion_exports__4",
73+
"type": "[ID!]!"
74+
}
75+
],
76+
"path": [
77+
"nodes"
78+
],
79+
"requires": [
80+
{
81+
"variable": "__fusion_exports__4"
82+
}
83+
]
84+
}
85+
]
86+
},
87+
{
88+
"type": "Compose",
89+
"selectionSetIds": [
90+
4
91+
]
92+
},
93+
{
94+
"type": "Resolve",
95+
"subgraph": "Shipping",
96+
"document": "query Requires_3($__fusion_exports__1: Int!, $__fusion_exports__2: Int!, $__fusion_exports__4: ID!) { productById(id: $__fusion_exports__4) { deliveryEstimate(size: $__fusion_exports__1, weight: $__fusion_exports__2, zip: \u002212345\u0022) { min max } } }",
97+
"selectionSetId": 2,
98+
"path": [
99+
"productById"
100+
],
101+
"requires": [
102+
{
103+
"variable": "__fusion_exports__1"
104+
},
105+
{
106+
"variable": "__fusion_exports__2"
107+
},
108+
{
109+
"variable": "__fusion_exports__4"
110+
}
111+
]
112+
},
113+
{
114+
"type": "Compose",
115+
"selectionSetIds": [
116+
2
117+
]
118+
}
119+
]
120+
}
121+
}
122+
---------------

0 commit comments

Comments
 (0)