-
Notifications
You must be signed in to change notification settings - Fork 2
/
resolvers.ts
83 lines (81 loc) · 2.71 KB
/
resolvers.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { createFolder } from './folders/mutations/create-folder';
import { deleteFolders } from './folders/mutations/delete-folders';
import { updateFolder } from './folders/mutations/update-folder';
import { findFolder } from './folders/queries/find-folder';
import { listDirectory } from './folders/queries/list-directory';
import { listFolders } from './folders/queries/list-folders';
import { subFoldersCountResolver } from './folders/resolvers';
import { subscribeToNewsletter } from './newsletter/mutations/subscribe';
import { createSnippet } from './snippets/mutations/create-snippet';
import { deleteSnippet } from './snippets/mutations/delete-snippet';
import { updateSnippet } from './snippets/mutations/update-snippet';
import { findSnippet } from './snippets/queries/find-snippet';
import { mySnippets } from './snippets/queries/my-snippets';
import { publicSnippets } from './snippets/queries/public-snippets';
import { dateScalar } from './types/date';
import { loginUser } from './users/mutations/login-user';
import { logoutUser } from './users/mutations/logout-user';
import { signupUser } from './users/mutations/signup-user';
import { authenticatedUser } from './users/queries/authenticated-user';
import { Resolvers } from '../types/graphql';
const resolvers: Resolvers = {
Date: dateScalar,
Folder: {
parent: (folder, _args, context) => {
return context.db.folder.findById(folder.parentId);
},
subFolders: (folder, _args, context) => {
return context.db.folder.findSubFolders(folder.id);
},
subFoldersCount: subFoldersCountResolver,
user: (folder, _args, context) => {
return context.db.user.findById(folder.userId);
},
},
Mutation: {
createFolder,
createSnippet,
deleteFolders,
deleteSnippet,
loginUser,
logoutUser,
signupUser,
subscribeToNewsletter,
updateFolder,
updateSnippet,
},
Query: {
authenticatedUser,
findFolder,
findSnippet,
hello: () => 'Hello from Snipcode',
listDirectory,
listFolders,
mySnippets,
ping: () => 'pong',
publicSnippets,
},
Snippet: {
contentHighlighted: (snippet) => {
return snippet.contentHtml;
},
folder: (snippet, _args, context) => {
return context.db.folder.findById(snippet.folderId);
},
user: (snippet, _args, context) => {
return context.db.user.findById(snippet.userId);
},
},
User: {
folders: (user, _args, context) => {
return context.db.folder.findUserFolders(user.id);
},
role: (user, _args, context) => {
return context.db.role.findById(user.roleId);
},
rootFolder: (user, _args, context) => {
return context.db.folder.findUserRootFolder(user.id);
},
},
};
export default resolvers;