forked from the-guild-org/graphql-federation-gateway-audit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathb.subgraph.ts
65 lines (56 loc) · 1.35 KB
/
b.subgraph.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { createSubgraph } from "../../subgraph.js";
import { animals, medias } from "./data.js";
export default createSubgraph("b", {
typeDefs: /* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable", "@provides", "@external"]
)
type Query {
media: Media @shareable @provides(fields: "animals { id name }")
}
interface Media {
id: ID!
animals: [Animal]
}
interface Animal {
id: ID!
name: String
}
type Book implements Media {
id: ID! @shareable
animals: [Animal] @external
}
type Dog implements Animal {
id: ID! @external
name: String @external
}
type Cat implements Animal {
id: ID! @external
name: String @external
}
`,
resolvers: {
Query: {
media() {
const media = medias[0];
return {
__typename: media.__typename,
id: media.id,
animals: media.animals.map((animalId) => {
const animal = animals.find((a) => a.id === animalId);
if (!animal) {
return null;
}
return {
__typename: animal.__typename,
id: animal.id,
name: animal.name,
};
}),
};
},
},
},
});