Skip to content

Commit 478f898

Browse files
committed
test: @override edge case
1 parent 3e224c8 commit 478f898

File tree

1 file changed

+90
-19
lines changed

1 file changed

+90
-19
lines changed

__tests__/composition.spec.ts

Lines changed: 90 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,77 @@ testImplementations((api) => {
248248
`);
249249
});
250250

251+
test("@override(from:) no usedOverridden in case the overriden field is @external", () => {
252+
const result = composeServices([
253+
{
254+
name: "a",
255+
typeDefs: parse(/* GraphQL */ `
256+
extend schema
257+
@link(url: "https://specs.apollo.dev/link/v1.0")
258+
@link(
259+
url: "https://specs.apollo.dev/federation/v2.3"
260+
import: ["@tag", "@external", "@shareable", "@key", "@override"]
261+
)
262+
263+
type Query {
264+
ping: String
265+
}
266+
267+
interface Base {
268+
id: String!
269+
items: [String]
270+
}
271+
272+
type CollectionTemplateTree implements Base
273+
@key(fields: "id")
274+
@shareable {
275+
id: String!
276+
items: [String] @override(from: "b")
277+
}
278+
`),
279+
},
280+
{
281+
name: "b",
282+
typeDefs: parse(/* GraphQL */ `
283+
extend schema
284+
@link(url: "https://specs.apollo.dev/link/v1.0")
285+
@link(
286+
url: "https://specs.apollo.dev/federation/v2.0"
287+
import: ["@tag", "@external", "@shareable", "@key"]
288+
)
289+
290+
type Query {
291+
pong: String
292+
}
293+
294+
interface Base {
295+
id: String!
296+
items: [String]
297+
}
298+
299+
type CollectionTemplateTree implements Base
300+
@key(fields: "id")
301+
@shareable {
302+
id: String!
303+
items: [String] @external
304+
}
305+
`),
306+
},
307+
]);
308+
309+
expect(result.errors).toEqual(undefined);
310+
const line = result
311+
.supergraphSdl!.split("\n")
312+
.find((line) => line.includes("items: [String] @join__field"));
313+
314+
expect(line).toContain('@join__field(graph: A, override: "b")');
315+
expect(line).toContain("@join__field(graph: B, external: true)");
316+
// The usedOverridden should not appear
317+
expect(line).not.toContain(
318+
"@join__field(graph: B, usedOverridden: true, external: true)",
319+
);
320+
});
321+
251322
test("@join__field(external: true) when field is overridden", () => {
252323
let result = composeServices([
253324
{
@@ -7382,25 +7453,25 @@ testImplementations((api) => {
73827453
typeDefs: parse(/* GraphQL */ `
73837454
extend schema
73847455
@link(
7385-
url: "https://specs.apollo.dev/federation/v2.3"
7386-
import: ["@key", "@shareable"]
7456+
url: "https://specs.apollo.dev/federation/v2.3"
7457+
import: ["@key", "@shareable"]
73877458
)
73887459
type Note @key(fields: "id") @shareable {
73897460
id: ID!
73907461
name: String
73917462
author: User
73927463
}
73937464
type User @key(fields: "id") {
7394-
id: ID!
7395-
name: String
7465+
id: ID!
7466+
name: String
73967467
}
7397-
type PrivateNote @key(fields: "id") @shareable {
7398-
id: ID!
7399-
note: Note
7400-
}
7401-
type Query {
7402-
note: Note @shareable
7403-
privateNote: PrivateNote @shareable
7468+
type PrivateNote @key(fields: "id") @shareable {
7469+
id: ID!
7470+
note: Note
7471+
}
7472+
type Query {
7473+
note: Note @shareable
7474+
privateNote: PrivateNote @shareable
74047475
}
74057476
`),
74067477
},
@@ -7425,9 +7496,9 @@ testImplementations((api) => {
74257496
result = api.composeServices([
74267497
{
74277498
name: "foo",
7428-
typeDefs: parse(/* GraphQL */ `
7499+
typeDefs: parse(/* GraphQL */ `
74297500
extend schema
7430-
@link(
7501+
@link(
74317502
url: "https://specs.apollo.dev/federation/v2.3"
74327503
import: ["@key", "@external", "@provides", "@shareable"]
74337504
)
@@ -7442,8 +7513,8 @@ testImplementations((api) => {
74427513
type PrivateNote @key(fields: "id") @shareable {
74437514
id: ID!
74447515
note: Note @provides(fields: "name author { id }")
7445-
}
7446-
type Query {
7516+
}
7517+
type Query {
74477518
note: Note @shareable
74487519
privateNote: PrivateNote @shareable
74497520
}
@@ -7461,8 +7532,8 @@ testImplementations((api) => {
74617532
id: ID!
74627533
name: String
74637534
author: User
7464-
}
7465-
type User @key(fields: "id") {
7535+
}
7536+
type User @key(fields: "id") {
74667537
id: ID!
74677538
name: String
74687539
}
@@ -7490,7 +7561,7 @@ testImplementations((api) => {
74907561
type Note @key(fields: "id") @shareable {
74917562
id: ID!
74927563
tag: String
7493-
}
7564+
}
74947565
`),
74957566
},
74967567
]);
@@ -7510,7 +7581,7 @@ testImplementations((api) => {
75107581
@join__field(external: true, graph: FOO)
75117582
@join__field(graph: BAR)
75127583
tag: String @join__field(graph: BAZ)
7513-
}
7584+
}
75147585
`);
75157586
});
75167587

0 commit comments

Comments
 (0)