|
1 |
| -const shortid = require('shortid') |
| 1 | +const channels = require('./channels') |
| 2 | +const cwd = require('./connectors/cwd') |
| 3 | +const folders = require('./connectors/folders') |
2 | 4 |
|
3 | 5 | module.exports = {
|
4 |
| - Counter: { |
5 |
| - countStr: counter => `Current count: ${counter.count}` |
| 6 | + Folder: { |
| 7 | + children: (folder, args, context) => folders.list(folder.path, context) |
6 | 8 | },
|
7 | 9 |
|
8 | 10 | Query: {
|
9 |
| - hello: (root, { name }) => `Hello ${name || 'World'}!`, |
10 |
| - messages: (root, args, { db }) => db.get('messages').value(), |
11 |
| - uploads: (root, args, { db }) => db.get('uploads').value() |
| 11 | + cwd: () => cwd.get(), |
| 12 | + folderCurrent: (root, args, context) => folders.getCurrent(args, context) |
12 | 13 | },
|
13 | 14 |
|
14 | 15 | Mutation: {
|
15 |
| - messageAdd: (root, { input }, { pubsub, db }) => { |
16 |
| - const message = { |
17 |
| - id: shortid.generate(), |
18 |
| - text: input.text |
19 |
| - } |
20 |
| - |
21 |
| - db |
22 |
| - .get('messages') |
23 |
| - .push(message) |
24 |
| - .last() |
25 |
| - .write() |
26 |
| - |
27 |
| - pubsub.publish('messages', { messageAdded: message }) |
28 |
| - |
29 |
| - return message |
30 |
| - }, |
31 |
| - |
32 |
| - singleUpload: (root, { file }, { processUpload }) => processUpload(file), |
33 |
| - multipleUpload: (root, { files }, { processUpload }) => Promise.all(files.map(processUpload)) |
| 16 | + folderOpen: (root, { path }, context) => folders.open(path, context), |
| 17 | + folderOpenParent: (root, args, context) => folders.openParent(cwd.get(), context) |
34 | 18 | },
|
35 | 19 |
|
36 | 20 | Subscription: {
|
37 |
| - counter: { |
38 |
| - subscribe: (parent, args, { pubsub }) => { |
39 |
| - const channel = Math.random().toString(36).substring(2, 15) // random channel name |
40 |
| - let count = 0 |
41 |
| - setInterval(() => pubsub.publish( |
42 |
| - channel, |
43 |
| - { |
44 |
| - // eslint-disable-next-line no-plusplus |
45 |
| - counter: { count: count++ } |
46 |
| - } |
47 |
| - ), 2000) |
48 |
| - return pubsub.asyncIterator(channel) |
49 |
| - } |
50 |
| - }, |
51 |
| - |
52 |
| - messageAdded: { |
53 |
| - subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator('messages') |
| 21 | + cwdChanged: { |
| 22 | + subscribe: (parent, args, { pubsub }) => pubsub.asyncIterator(channels.CWD_CHANGED) |
54 | 23 | }
|
55 | 24 | }
|
56 | 25 | }
|
0 commit comments