-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraphql.js
43 lines (40 loc) · 1.14 KB
/
graphql.js
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
export const resolvers = {
Viewer: {
items: async (parent, args, context, info) => {
const items = await context.loaders.items();
return items.filter(x => x.email === context.viewer.id);
}
},
Item: {
items: (parent, args, context, info) => context.loaders.items()
},
Query: {
item: async (parent, args, context, info) =>
(await context.loaders.items()).find(x => x.id == args.id),
items: (parent, args, context, info) => context.loaders.items(),
viewer: (parent, args, context, info) => args
},
Mutation: {
upsertItem: (parent, args, context, info) => {
context.pubsub.publish('itemUpsertedChannel', args.input);
return args.input;
}
},
Subscription: {
onItemUpserted: async (source, args, context, info) =>
(await context.loaders.items()).find(x => x.id == source.id)
}
};
export const loaders = {
items: async () => [
{id: 1, email: 'go@subkit.io', value: {some: 'something'}},
{id: 2},
{id: 3}
]
};
export const channels = {
onItemUpserted: (options, args) => ({
itemUpsertedChannel: {filter: event => true}
})
};
export const directives = {};