Skip to content

Commit 8bd6e1c

Browse files
clenfestclaudetninesling
authored
port compose.test.ts tests (#8295)
Co-authored-by: Claude <[email protected]> Co-authored-by: Taylor Ninesling <[email protected]>
1 parent a86b538 commit 8bd6e1c

23 files changed

+5531
-0
lines changed

apollo-federation/tests/composition/compose_auth.rs

Lines changed: 846 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
use insta::assert_snapshot;
2+
3+
use super::ServiceDefinition;
4+
use super::compose_as_fed2_subgraphs;
5+
use super::extract_subgraphs_from_supergraph_result;
6+
use super::print_sdl;
7+
8+
#[test]
9+
#[ignore = "until merge implementation completed"]
10+
fn generates_a_valid_supergraph() {
11+
let subgraph1 = ServiceDefinition {
12+
name: "Subgraph1",
13+
type_defs: r#"
14+
type Query {
15+
t: T
16+
}
17+
18+
type T @key(fields: "k") {
19+
k: ID
20+
}
21+
22+
type S {
23+
x: Int
24+
}
25+
26+
union U = S | T
27+
"#,
28+
};
29+
30+
let subgraph2 = ServiceDefinition {
31+
name: "Subgraph2",
32+
type_defs: r#"
33+
type T @key(fields: "k") {
34+
k: ID
35+
a: Int
36+
b: String
37+
}
38+
39+
enum E {
40+
V1
41+
V2
42+
}
43+
"#,
44+
};
45+
46+
let result = compose_as_fed2_subgraphs(&[subgraph1, subgraph2]);
47+
let supergraph = result.expect("Expected composition to succeed");
48+
49+
// Test supergraph SDL structure
50+
assert_snapshot!(print_sdl(supergraph.schema().schema()));
51+
52+
// Test API schema structure
53+
let api_schema = supergraph
54+
.to_api_schema(Default::default())
55+
.expect("Expected API schema generation to succeed");
56+
assert_snapshot!(print_sdl(api_schema.schema()));
57+
}
58+
59+
#[test]
60+
#[ignore = "until merge implementation completed"]
61+
fn preserves_descriptions() {
62+
let subgraph1 = ServiceDefinition {
63+
name: "Subgraph1",
64+
type_defs: r#"
65+
"The foo directive description"
66+
directive @foo(url: String) on FIELD
67+
68+
"A cool schema"
69+
schema {
70+
query: Query
71+
}
72+
73+
"""
74+
Available queries
75+
Not much yet
76+
"""
77+
type Query {
78+
"Returns tea"
79+
t(
80+
"An argument that is very important"
81+
x: String!
82+
): String
83+
}
84+
"#,
85+
};
86+
87+
let subgraph2 = ServiceDefinition {
88+
name: "Subgraph2",
89+
type_defs: r#"
90+
"The foo directive description"
91+
directive @foo(url: String) on FIELD
92+
93+
"An enum"
94+
enum E {
95+
"The A value"
96+
A
97+
"The B value"
98+
B
99+
}
100+
"#,
101+
};
102+
103+
let result = compose_as_fed2_subgraphs(&[subgraph1, subgraph2]);
104+
let supergraph = result.expect("Expected composition to succeed");
105+
let api_schema = supergraph
106+
.to_api_schema(Default::default())
107+
.expect("Expected API schema generation to succeed");
108+
assert_snapshot!(print_sdl(api_schema.schema()));
109+
}
110+
111+
#[test]
112+
#[ignore = "until merge implementation completed"]
113+
fn no_hint_raised_when_merging_empty_description() {
114+
let subgraph1 = ServiceDefinition {
115+
name: "Subgraph1",
116+
type_defs: r#"
117+
schema {
118+
query: Query
119+
}
120+
121+
""
122+
type T {
123+
a: String @shareable
124+
}
125+
126+
type Query {
127+
"Returns tea"
128+
t(
129+
"An argument that is very important"
130+
x: String!
131+
): T
132+
}
133+
"#,
134+
};
135+
136+
let subgraph2 = ServiceDefinition {
137+
name: "Subgraph2",
138+
type_defs: r#"
139+
"Type T"
140+
type T {
141+
a: String @shareable
142+
}
143+
"#,
144+
};
145+
146+
let result = compose_as_fed2_subgraphs(&[subgraph1, subgraph2]);
147+
let supergraph = result.expect("Expected composition to succeed");
148+
149+
// Verify that no hints are raised when merging empty description with non-empty description
150+
assert_eq!(
151+
supergraph.hints().len(),
152+
0,
153+
"Expected no hints but got: {:?}",
154+
supergraph.hints()
155+
);
156+
}
157+
158+
#[test]
159+
#[ignore = "until merge implementation completed"]
160+
fn include_types_from_different_subgraphs() {
161+
let subgraph_a = ServiceDefinition {
162+
name: "subgraphA",
163+
type_defs: r#"
164+
type Query {
165+
products: [Product!]
166+
}
167+
168+
type Product {
169+
sku: String!
170+
name: String!
171+
}
172+
"#,
173+
};
174+
175+
let subgraph_b = ServiceDefinition {
176+
name: "subgraphB",
177+
type_defs: r#"
178+
type User {
179+
name: String
180+
email: String!
181+
}
182+
"#,
183+
};
184+
185+
let result = compose_as_fed2_subgraphs(&[subgraph_a, subgraph_b]);
186+
let supergraph = result.expect("Expected composition to succeed");
187+
let api_schema = supergraph
188+
.to_api_schema(Default::default())
189+
.expect("Expected API schema generation to succeed");
190+
assert_snapshot!(print_sdl(api_schema.schema()));
191+
192+
// Validate extracted subgraphs contain proper federation directives
193+
let extracted_subgraphs = extract_subgraphs_from_supergraph_result(&supergraph)
194+
.expect("Expected subgraph extraction to succeed");
195+
196+
let subgraph_a_extracted = extracted_subgraphs
197+
.get("subgraphA")
198+
.expect("Expected subgraphA to be present in extracted subgraphs");
199+
assert_snapshot!(print_sdl(subgraph_a_extracted.schema.schema()));
200+
201+
let subgraph_b_extracted = extracted_subgraphs
202+
.get("subgraphB")
203+
.expect("Expected subgraphB to be present in extracted subgraphs");
204+
assert_snapshot!(print_sdl(subgraph_b_extracted.schema.schema()));
205+
}
206+
207+
#[test]
208+
#[ignore = "until merge implementation completed"]
209+
fn doesnt_leave_federation_directives_in_the_final_schema() {
210+
let subgraph_a = ServiceDefinition {
211+
name: "subgraphA",
212+
type_defs: r#"
213+
type Query {
214+
products: [Product!] @provides(fields: "name")
215+
}
216+
217+
type Product @key(fields: "sku") {
218+
sku: String!
219+
name: String! @external
220+
}
221+
"#,
222+
};
223+
224+
let subgraph_b = ServiceDefinition {
225+
name: "subgraphB",
226+
type_defs: r#"
227+
type Product @key(fields: "sku") {
228+
sku: String!
229+
name: String! @shareable
230+
}
231+
"#,
232+
};
233+
234+
let result = compose_as_fed2_subgraphs(&[subgraph_a, subgraph_b]);
235+
let supergraph = result.expect("Expected composition to succeed");
236+
let api_schema = supergraph
237+
.to_api_schema(Default::default())
238+
.expect("Expected API schema generation to succeed");
239+
assert_snapshot!(print_sdl(api_schema.schema()));
240+
241+
// Validate that federation directives (@provides, @key, @external, @shareable)
242+
// are properly rebuilt in the extracted subgraphs
243+
let extracted_subgraphs = extract_subgraphs_from_supergraph_result(&supergraph)
244+
.expect("Expected subgraph extraction to succeed");
245+
246+
let subgraph_a_extracted = extracted_subgraphs
247+
.get("subgraphA")
248+
.expect("Expected subgraphA to be present in extracted subgraphs");
249+
assert_snapshot!(print_sdl(subgraph_a_extracted.schema.schema()));
250+
251+
let subgraph_b_extracted = extracted_subgraphs
252+
.get("subgraphB")
253+
.expect("Expected subgraphB to be present in extracted subgraphs");
254+
assert_snapshot!(print_sdl(subgraph_b_extracted.schema.schema()));
255+
}
256+
257+
#[test]
258+
#[ignore = "until merge implementation completed"]
259+
fn merges_default_arguments_when_they_are_arrays() {
260+
let subgraph_a = ServiceDefinition {
261+
name: "subgraph-a",
262+
type_defs: r#"
263+
type Query {
264+
a: A @shareable
265+
}
266+
267+
type A @key(fields: "id") {
268+
id: ID
269+
get(ids: [ID] = []): [B] @external
270+
req: Int @requires(fields: "get { __typename }")
271+
}
272+
273+
type B @key(fields: "id", resolvable: false) {
274+
id: ID
275+
}
276+
"#,
277+
};
278+
279+
let subgraph_b = ServiceDefinition {
280+
name: "subgraph-b",
281+
type_defs: r#"
282+
type Query {
283+
a: A @shareable
284+
}
285+
286+
type A @key(fields: "id") {
287+
id: ID
288+
get(ids: [ID] = []): [B]
289+
}
290+
291+
type B @key(fields: "id") {
292+
id: ID
293+
}
294+
"#,
295+
};
296+
297+
let result = compose_as_fed2_subgraphs(&[subgraph_a, subgraph_b]);
298+
let _supergraph = result.expect("Expected composition to succeed");
299+
}

0 commit comments

Comments
 (0)