Skip to content

Commit 05e5429

Browse files
committed
test: inconsistency reproduction
1 parent 3e224c8 commit 05e5429

File tree

1 file changed

+134
-20
lines changed

1 file changed

+134
-20
lines changed

__tests__/composition.spec.ts

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

251+
test(`extend type causes additional @join__type(extension: true)`, () => {
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: ["@key"]
261+
)
262+
263+
type Query {
264+
a: String
265+
}
266+
267+
type MediaReference @key(fields: "assetId") {
268+
assetId: String!
269+
}
270+
`),
271+
},
272+
{
273+
name: "b",
274+
typeDefs: parse(/* GraphQL */ `
275+
extend schema
276+
@link(url: "https://specs.apollo.dev/link/v1.0")
277+
@link(
278+
url: "https://specs.apollo.dev/federation/v2.3"
279+
import: ["@key"]
280+
)
281+
282+
type Query {
283+
b: String
284+
}
285+
286+
type MediaReference @key(fields: "assetId") {
287+
assetId: String!
288+
}
289+
extend type MediaReference @key(fields: "assetId") {
290+
media: String
291+
}
292+
`),
293+
},
294+
]);
295+
296+
expect(result.errors).toEqual(undefined);
297+
expect(result.supergraphSdl).toContain(
298+
`@join__type(graph: B, key: "assetId", extension: true)`,
299+
);
300+
});
301+
302+
test(`@join__field(external: true) missing because of ???`, () => {
303+
let result = composeServices([
304+
{
305+
name: "a",
306+
typeDefs: parse(/* GraphQL */ `
307+
extend schema
308+
@link(
309+
url: "https://specs.apollo.dev/federation/v2.3"
310+
import: [
311+
"@key"
312+
"@requires"
313+
"@external"
314+
"@shareable"
315+
"@extends"
316+
]
317+
)
318+
319+
type Query {
320+
a: String
321+
}
322+
323+
type Order @extends @shareable @key(fields: "id") {
324+
id: ID! @external
325+
id2: ID @external
326+
orderProgress: String! @requires(fields: "id2")
327+
}
328+
`),
329+
},
330+
{
331+
name: "b",
332+
typeDefs: parse(/* GraphQL */ `
333+
extend schema
334+
@link(
335+
url: "https://specs.apollo.dev/federation/v2.3"
336+
import: ["@key", "@shareable"]
337+
)
338+
339+
type Query {
340+
b: String
341+
}
342+
343+
type Order @key(fields: "id") @key(fields: "id2") @shareable {
344+
id: ID!
345+
id2: ID
346+
countryCode: String!
347+
}
348+
`),
349+
},
350+
]);
351+
352+
assertCompositionSuccess(result);
353+
354+
console.log(result.supergraphSdl);
355+
356+
const line = result.supergraphSdl
357+
.split("\n")
358+
.find((line) => line.includes("id2: ID"));
359+
const [, remainder] = line!.split("id2: ID");
360+
361+
expect(remainder).toContain("@join__field(graph: A, external: true)");
362+
expect(remainder).toContain("@join__field(graph: B)");
363+
});
364+
251365
test("@join__field(external: true) when field is overridden", () => {
252366
let result = composeServices([
253367
{
@@ -7280,7 +7394,7 @@ testImplementations((api) => {
72807394
`);
72817395
});
72827396

7283-
test("external on non-key field of an entity type", () => {
7397+
test.only("external on non-key field of an entity type", () => {
72847398
/** "apollo" errors on this schema definition */
72857399
api.runIf("guild", () => {
72867400
let result = api.composeServices([
@@ -7382,25 +7496,25 @@ testImplementations((api) => {
73827496
typeDefs: parse(/* GraphQL */ `
73837497
extend schema
73847498
@link(
7385-
url: "https://specs.apollo.dev/federation/v2.3"
7386-
import: ["@key", "@shareable"]
7499+
url: "https://specs.apollo.dev/federation/v2.3"
7500+
import: ["@key", "@shareable"]
73877501
)
73887502
type Note @key(fields: "id") @shareable {
73897503
id: ID!
73907504
name: String
73917505
author: User
73927506
}
73937507
type User @key(fields: "id") {
7394-
id: ID!
7395-
name: String
7508+
id: ID!
7509+
name: String
73967510
}
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
7511+
type PrivateNote @key(fields: "id") @shareable {
7512+
id: ID!
7513+
note: Note
7514+
}
7515+
type Query {
7516+
note: Note @shareable
7517+
privateNote: PrivateNote @shareable
74047518
}
74057519
`),
74067520
},
@@ -7425,9 +7539,9 @@ testImplementations((api) => {
74257539
result = api.composeServices([
74267540
{
74277541
name: "foo",
7428-
typeDefs: parse(/* GraphQL */ `
7542+
typeDefs: parse(/* GraphQL */ `
74297543
extend schema
7430-
@link(
7544+
@link(
74317545
url: "https://specs.apollo.dev/federation/v2.3"
74327546
import: ["@key", "@external", "@provides", "@shareable"]
74337547
)
@@ -7442,8 +7556,8 @@ testImplementations((api) => {
74427556
type PrivateNote @key(fields: "id") @shareable {
74437557
id: ID!
74447558
note: Note @provides(fields: "name author { id }")
7445-
}
7446-
type Query {
7559+
}
7560+
type Query {
74477561
note: Note @shareable
74487562
privateNote: PrivateNote @shareable
74497563
}
@@ -7461,8 +7575,8 @@ testImplementations((api) => {
74617575
id: ID!
74627576
name: String
74637577
author: User
7464-
}
7465-
type User @key(fields: "id") {
7578+
}
7579+
type User @key(fields: "id") {
74667580
id: ID!
74677581
name: String
74687582
}
@@ -7490,7 +7604,7 @@ testImplementations((api) => {
74907604
type Note @key(fields: "id") @shareable {
74917605
id: ID!
74927606
tag: String
7493-
}
7607+
}
74947608
`),
74957609
},
74967610
]);
@@ -7510,7 +7624,7 @@ testImplementations((api) => {
75107624
@join__field(external: true, graph: FOO)
75117625
@join__field(graph: BAR)
75127626
tag: String @join__field(graph: BAZ)
7513-
}
7627+
}
75147628
`);
75157629
});
75167630

0 commit comments

Comments
 (0)