-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.ts
More file actions
40 lines (36 loc) · 1.09 KB
/
node.ts
File metadata and controls
40 lines (36 loc) · 1.09 KB
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
/**
* Node.js GraphQL API Starter Kit
* https://github.com/kriasoft/nodejs-api-starter
* Copyright © 2016-present Kriasoft | MIT License
*/
/* eslint-disable global-require */
import { nodeDefinitions, fromGlobalId } from 'graphql-relay';
import { assignType, getType } from './utils';
import { Context } from './context';
export const { nodeInterface, nodeField, nodesField } = nodeDefinitions(
(globalId, context: Context) => {
const { type, id } = fromGlobalId(globalId);
switch (type) {
case 'User':
return context.userById.load(id).then(assignType('User'));
case 'Story':
return context.storyById.load(id).then(assignType('Story'));
case 'Comment':
return context.commentById.load(id).then(assignType('Comment'));
default:
return null;
}
},
obj => {
switch (getType(obj)) {
case 'User':
return require('./types').UserType;
case 'Story':
return require('./types').StoryType;
case 'Comment':
return require('./types').CommentType;
default:
return null;
}
},
);