forked from the-guild-org/graphql-federation-gateway-audit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
a.subgraph.ts
42 lines (37 loc) · 848 Bytes
/
a.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
import { createSubgraph } from "../../subgraph.js";
import { products } from "./data.js";
export default createSubgraph("a", {
typeDefs: /* GraphQL */ `
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key"])
type Query {
product: Product
}
type Product @key(fields: "id") {
id: ID!
price: Float!
}
`,
resolvers: {
Query: {
product() {
return {
id: products[0].id,
price: products[0].price,
};
},
},
Product: {
__resolveReference(key: { id: string }) {
const product = products.find((product) => product.id === key.id);
if (!product) {
return null;
}
return {
id: product.id,
price: product.price,
};
},
},
},
});