forked from the-guild-org/graphql-federation-gateway-audit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmagazines.subgraph.ts
47 lines (43 loc) · 1.01 KB
/
magazines.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
import { createSubgraph } from "../../subgraph.js";
import { magazines } from "./data.js";
export default createSubgraph("magazines", {
typeDefs: /* GraphQL */ `
schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable"]
) {
query: Query
}
type Magazine @key(fields: "id") {
id: ID!
title: String
}
type Query {
magazines: [Magazine]
}
`,
resolvers: {
Query: {
magazines() {
return magazines.map((magazine) => ({
__typename: magazine.__typename,
id: magazine.id,
title: magazine.title,
}));
},
},
Magazine: {
__resolveReference(key: { id: string }) {
const magazine = magazines.find((magazine) => magazine.id === key.id);
return magazine
? {
__typename: magazine.__typename,
id: magazine.id,
title: magazine.title,
}
: null;
},
},
},
});