Skip to content

Commit 7d640bf

Browse files
authored
Fix a child data type field not being accessible via interfaceObject (#82)
Closes #80
1 parent 1487685 commit 7d640bf

File tree

8 files changed

+106
-49
lines changed

8 files changed

+106
-49
lines changed

.changeset/warm-seahorses-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@theguild/federation-composition": patch
3+
---
4+
5+
Fix a child data type field not being accessible via interfaceObject

__tests__/interface-object-composition.spec.ts

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ testImplementations(api => {
6767
)
6868
6969
type Query {
70-
hello: String
70+
hello: MyInterface
7171
}
7272
7373
interface MyInterface @key(fields: "id") {
@@ -90,7 +90,7 @@ testImplementations(api => {
9090
import: ["@key", "@interfaceObject"]
9191
)
9292
type Query {
93-
otherField: String
93+
otherField: MyInterface
9494
}
9595
9696
type MyInterface @key(fields: "id") @interfaceObject {
@@ -120,7 +120,7 @@ testImplementations(api => {
120120
)
121121
122122
type Query {
123-
hello: String
123+
hello: MyInterface
124124
}
125125
126126
interface MyInterface @key(fields: "id") {
@@ -189,7 +189,7 @@ testImplementations(api => {
189189
extend schema @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key"])
190190
191191
type Query {
192-
hello: String
192+
hello: MyInterface
193193
}
194194
195195
interface MyInterface @key(fields: "id") {
@@ -212,7 +212,7 @@ testImplementations(api => {
212212
import: ["@key", "@interfaceObject"]
213213
)
214214
type Query {
215-
otherField: String
215+
otherField: MyInterface
216216
}
217217
218218
type MyInterface @key(fields: "id") @interfaceObject {
@@ -237,10 +237,10 @@ testImplementations(api => {
237237
)
238238
239239
type Query {
240-
hello: String
240+
hello: MyInterface
241241
}
242242
243-
interface MyInterface {
243+
interface MyInterface @key(fields: "id") {
244244
id: ID!
245245
field: String
246246
}
@@ -260,7 +260,7 @@ testImplementations(api => {
260260
import: ["@key", "@interfaceObject"]
261261
)
262262
type Query {
263-
otherField: String
263+
otherField: MyInterface
264264
}
265265
266266
type MyInterface @key(fields: "id") @interfaceObject {
@@ -291,7 +291,7 @@ testImplementations(api => {
291291
)
292292
293293
type Query {
294-
hello: String
294+
hello: MyInterface
295295
}
296296
297297
interface MyInterface @key(fields: "id") {
@@ -309,7 +309,7 @@ testImplementations(api => {
309309
import: ["@key", "@interfaceObject"]
310310
)
311311
type Query {
312-
otherField: String
312+
otherField: MyInterface
313313
}
314314
315315
type MyInterface @key(fields: "id") @interfaceObject {
@@ -364,7 +364,7 @@ testImplementations(api => {
364364
import: ["@key", "@interfaceObject"]
365365
)
366366
type Query {
367-
otherField: String
367+
otherField: MyInterface
368368
}
369369
370370
type MyInterface @key(fields: "id") @interfaceObject {
@@ -402,7 +402,7 @@ testImplementations(api => {
402402
)
403403
404404
type Query {
405-
hello: String
405+
hello: MyInterface
406406
}
407407
408408
interface MyInterface {
@@ -425,7 +425,7 @@ testImplementations(api => {
425425
import: ["@key", "@interfaceObject"]
426426
)
427427
type Query {
428-
otherField: String
428+
otherField: MyInterface
429429
}
430430
431431
type MyInterface @interfaceObject {
@@ -460,7 +460,7 @@ testImplementations(api => {
460460
)
461461
462462
type Query {
463-
hello: String
463+
hello: MyInterface
464464
}
465465
466466
interface MyInterface @key(fields: "id") {
@@ -483,7 +483,7 @@ testImplementations(api => {
483483
import: ["@key", "@interfaceObject"]
484484
)
485485
type Query {
486-
otherField: String
486+
otherField: MyInterface
487487
}
488488
489489
type MyInterface @key(fields: "id") @interfaceObject {
@@ -515,6 +515,56 @@ testImplementations(api => {
515515
}
516516
`);
517517
});
518+
519+
test('interface type is present on other subgraph with @key directive. Should succeed and add fields from a child of an interfaceObject', () => {
520+
const result = api.composeServices([
521+
{
522+
name: 'a',
523+
typeDefs: parse(/* GraphQL */ `
524+
extend schema
525+
@link(
526+
url: "https://specs.apollo.dev/federation/v2.6"
527+
import: ["@key", "@interfaceObject"]
528+
)
529+
530+
interface Media @key(fields: "id") {
531+
id: ID!
532+
title: String!
533+
}
534+
535+
type Book implements Media @key(fields: "id") {
536+
id: ID!
537+
title: String!
538+
}
539+
`),
540+
},
541+
{
542+
name: 'b',
543+
typeDefs: parse(/* GraphQL */ `
544+
extend schema
545+
@link(
546+
url: "https://specs.apollo.dev/federation/v2.6"
547+
import: ["@key", "@interfaceObject"]
548+
)
549+
550+
type Media @key(fields: "id") @interfaceObject {
551+
id: ID!
552+
reviews: [Review!]!
553+
}
554+
555+
type Review {
556+
score: Int!
557+
}
558+
559+
type Query {
560+
topRatedMedia: [Media!]!
561+
}
562+
`),
563+
},
564+
]);
565+
566+
assertCompositionSuccess(result);
567+
});
518568
});
519569

520570
describe(`fields contribution`, () => {
@@ -530,7 +580,7 @@ testImplementations(api => {
530580
)
531581
532582
type Query {
533-
hello: String
583+
hello: MyInterface
534584
}
535585
536586
interface MyInterface @key(fields: "id") {
@@ -553,7 +603,7 @@ testImplementations(api => {
553603
import: ["@key", "@interfaceObject"]
554604
)
555605
type Query {
556-
otherField: String
606+
otherField: MyInterface
557607
}
558608
559609
type MyInterface @key(fields: "id") @interfaceObject {
@@ -571,7 +621,7 @@ testImplementations(api => {
571621
import: ["@key", "@interfaceObject"]
572622
)
573623
type Query {
574-
someNewField: String
624+
someNewField: MyInterface
575625
}
576626
577627
type MyInterface @key(fields: "id") @interfaceObject {

__tests__/subgraph/link-directive.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ testVersions((api, version) => {
246246
errors: expect.arrayContaining([
247247
expect.objectContaining({
248248
message: expect.stringContaining(
249-
`[users] Invalid version v6.9 for the federation feature in @link direction on schema`,
249+
'[users] Invalid version v6.9 for the federation feature in @link directive on schema',
250250
),
251251
extensions: expect.objectContaining({
252252
code: 'UNKNOWN_FEDERATION_LINK_VERSION',

__tests__/supergraph/errors/INVALID_FIELD_SHARING.spec.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ testVersions((api, version) => {
1919
url: "https://specs.apollo.dev/federation/${version}"
2020
import: ["@key", "@shareable"]
2121
)
22-
22+
2323
type Query {
2424
users: [User]
2525
}
26-
26+
2727
type User @key(fields: "id") {
2828
id: ID
2929
profile: Profile
3030
}
31-
31+
3232
type Profile @shareable {
3333
name: String
3434
}
@@ -42,12 +42,12 @@ testVersions((api, version) => {
4242
url: "https://specs.apollo.dev/federation/${version}"
4343
import: ["@key", "@shareable"]
4444
)
45-
45+
4646
type User @key(fields: "id") {
4747
id: ID
4848
profile: Profile
4949
}
50-
50+
5151
type Profile @shareable {
5252
name: String
5353
}
@@ -79,11 +79,11 @@ testVersions((api, version) => {
7979
url: "https://specs.apollo.dev/federation/${version}"
8080
import: ["@key"]
8181
)
82-
82+
8383
type Query {
8484
user: User
8585
}
86-
86+
8787
type User {
8888
id: ID!
8989
name: String
@@ -98,12 +98,12 @@ testVersions((api, version) => {
9898
url: "https://specs.apollo.dev/federation/${version}"
9999
import: ["@key", "@shareable"]
100100
)
101-
101+
102102
type User @key(fields: "id") {
103103
id: ID!
104104
comments: [String]
105105
}
106-
106+
107107
type Query {
108108
users: [User]
109109
}
@@ -135,11 +135,11 @@ testVersions((api, version) => {
135135
url: "https://specs.apollo.dev/federation/${version}"
136136
import: ["@key", "@shareable"]
137137
)
138-
138+
139139
extend type Query {
140140
foo: Foo
141141
}
142-
142+
143143
type Foo @shareable @key(fields: "id") {
144144
id: ID!
145145
name: String
@@ -154,11 +154,11 @@ testVersions((api, version) => {
154154
url: "https://specs.apollo.dev/federation/${version}"
155155
import: ["@key", "@shareable", "@override"]
156156
)
157-
157+
158158
extend type Query {
159159
foo: Foo @override(from: "noop")
160160
}
161-
161+
162162
type Foo @shareable @key(fields: "id") {
163163
id: ID!
164164
name: String
@@ -173,7 +173,7 @@ testVersions((api, version) => {
173173
url: "https://specs.apollo.dev/federation/${version}"
174174
import: ["@key", "@shareable"]
175175
)
176-
176+
177177
type Query {
178178
noop: String
179179
}
@@ -205,7 +205,7 @@ testVersions((api, version) => {
205205
url: "https://specs.apollo.dev/federation/${version}"
206206
import: ["@shareable"]
207207
)
208-
208+
209209
extend type Note {
210210
url: String!
211211
}
@@ -382,7 +382,9 @@ testVersions((api, version) => {
382382
errors: expect.arrayContaining([
383383
expect.objectContaining({
384384
message: expect.stringContaining(
385-
`Fields on root level subscription object cannot be marked as shareable`,
385+
api.library === 'guild'
386+
? `Fields on root level subscription object cannot be marked as shareable`
387+
: 'Non-shareable field "Subscription.event" is resolved from multiple subgraphs: it is resolved from subgraphs "bar" and "foo" and defined as non-shareable in all of them',
386388
),
387389
extensions: expect.objectContaining({
388390
code: 'INVALID_FIELD_SHARING',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"lodash.sortby": "^4.7.0"
6969
},
7070
"devDependencies": {
71-
"@apollo/composition": "2.6.2",
71+
"@apollo/composition": "2.9.3",
7272
"@changesets/changelog-github": "0.4.8",
7373
"@changesets/cli": "2.26.2",
7474
"@theguild/prettier-config": "2.0.1",

0 commit comments

Comments
 (0)