forked from the-guild-org/graphql-federation-gateway-audit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
accounts.subgraph.ts
48 lines (43 loc) · 940 Bytes
/
accounts.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
import { createSubgraph } from "../../subgraph.js";
import { users } from "./data.js";
export default createSubgraph("accounts", {
typeDefs: /* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable"]
)
type Query {
me: User
}
type User @key(fields: "id") {
id: ID!
name: String
username: String @shareable
}
`,
resolvers: {
Query: {
me() {
return {
id: users[0].id,
name: users[0].name,
username: users[0].username,
};
},
},
User: {
__resolveReference(key: { id: string }) {
const user = users.find((u) => u.id === key.id);
if (!user) {
return null;
}
return {
id: user.id,
name: user.name,
username: user.username,
};
},
},
},
});