Skip to content

Commit d4d4f1d

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

File tree

1 file changed

+86
-19
lines changed

1 file changed

+86
-19
lines changed

__tests__/composition.spec.ts

Lines changed: 86 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,73 @@ 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 Object implements Base @key(fields: "id") @shareable {
273+
id: String!
274+
items: [String] @override(from: "b")
275+
}
276+
`),
277+
},
278+
{
279+
name: "b",
280+
typeDefs: parse(/* GraphQL */ `
281+
extend schema
282+
@link(url: "https://specs.apollo.dev/link/v1.0")
283+
@link(
284+
url: "https://specs.apollo.dev/federation/v2.0"
285+
import: ["@tag", "@external", "@shareable", "@key"]
286+
)
287+
288+
type Query {
289+
pong: String
290+
}
291+
292+
interface Base {
293+
id: String!
294+
items: [String]
295+
}
296+
297+
type Object implements Base @key(fields: "id") @shareable {
298+
id: String!
299+
items: [String] @external
300+
}
301+
`),
302+
},
303+
]);
304+
305+
expect(result.errors).toEqual(undefined);
306+
const line = result
307+
.supergraphSdl!.split("\n")
308+
.find((line) => line.includes("items: [String] @join__field"));
309+
310+
expect(line).toContain('@join__field(graph: A, override: "b")');
311+
expect(line).toContain("@join__field(graph: B, external: true)");
312+
// The usedOverridden should not appear
313+
expect(line).not.toContain(
314+
"@join__field(graph: B, usedOverridden: true, external: true)",
315+
);
316+
});
317+
251318
test("@join__field(external: true) when field is overridden", () => {
252319
let result = composeServices([
253320
{
@@ -7382,25 +7449,25 @@ testImplementations((api) => {
73827449
typeDefs: parse(/* GraphQL */ `
73837450
extend schema
73847451
@link(
7385-
url: "https://specs.apollo.dev/federation/v2.3"
7386-
import: ["@key", "@shareable"]
7452+
url: "https://specs.apollo.dev/federation/v2.3"
7453+
import: ["@key", "@shareable"]
73877454
)
73887455
type Note @key(fields: "id") @shareable {
73897456
id: ID!
73907457
name: String
73917458
author: User
73927459
}
73937460
type User @key(fields: "id") {
7394-
id: ID!
7395-
name: String
7461+
id: ID!
7462+
name: String
73967463
}
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
7464+
type PrivateNote @key(fields: "id") @shareable {
7465+
id: ID!
7466+
note: Note
7467+
}
7468+
type Query {
7469+
note: Note @shareable
7470+
privateNote: PrivateNote @shareable
74047471
}
74057472
`),
74067473
},
@@ -7425,9 +7492,9 @@ testImplementations((api) => {
74257492
result = api.composeServices([
74267493
{
74277494
name: "foo",
7428-
typeDefs: parse(/* GraphQL */ `
7495+
typeDefs: parse(/* GraphQL */ `
74297496
extend schema
7430-
@link(
7497+
@link(
74317498
url: "https://specs.apollo.dev/federation/v2.3"
74327499
import: ["@key", "@external", "@provides", "@shareable"]
74337500
)
@@ -7442,8 +7509,8 @@ testImplementations((api) => {
74427509
type PrivateNote @key(fields: "id") @shareable {
74437510
id: ID!
74447511
note: Note @provides(fields: "name author { id }")
7445-
}
7446-
type Query {
7512+
}
7513+
type Query {
74477514
note: Note @shareable
74487515
privateNote: PrivateNote @shareable
74497516
}
@@ -7461,8 +7528,8 @@ testImplementations((api) => {
74617528
id: ID!
74627529
name: String
74637530
author: User
7464-
}
7465-
type User @key(fields: "id") {
7531+
}
7532+
type User @key(fields: "id") {
74667533
id: ID!
74677534
name: String
74687535
}
@@ -7490,7 +7557,7 @@ testImplementations((api) => {
74907557
type Note @key(fields: "id") @shareable {
74917558
id: ID!
74927559
tag: String
7493-
}
7560+
}
74947561
`),
74957562
},
74967563
]);
@@ -7510,7 +7577,7 @@ testImplementations((api) => {
75107577
@join__field(external: true, graph: FOO)
75117578
@join__field(graph: BAR)
75127579
tag: String @join__field(graph: BAZ)
7513-
}
7580+
}
75147581
`);
75157582
});
75167583

0 commit comments

Comments
 (0)