/
resolvers.js
836 lines (778 loc) · 28.8 KB
/
resolvers.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
const rethink = require('rethinkdb');
const Boom = require('boom');
const GraphQLJSON = require('graphql-type-json');
const Promise = require('bluebird');
const { PubSub, withFilter } = require('graphql-subscriptions');
const axios = require('axios');
const helperFunctions = require('../auth-helpers');
const initSubscriptions = require('./subscriptions');
const config = require('../../config/default');
/**
* Helper function to retrieve all members of given table
* @param {string} table - The table name
* @return {array} The contents of the requested table
*/
function fetchAll(table) {
let connection;
return helperFunctions.getRethinkConnection()
.then((db) => {
connection = db;
return rethink.table(table).orderBy({ index: 'id' }).run(connection);
})
.then(cursor => cursor.toArray())
.then(res => connection.close().then(() => res));
}
/**
* Helper function to retrieve a single entry in a table
* @param {string} table - The table name
* @param {string} id - The entry id
* @return {object} The requested table entry
*/
function fetchOne(table, id) {
return helperFunctions.getRethinkConnection()
.then(connection => rethink.table(table).get(id).run(connection));
}
function fetchOnePipeline(id) {
return helperFunctions.getRethinkConnection()
.then(connection => rethink.table('pipelines')
.get(id)
// Populate computations subfield with computation meta information
.merge(pipeline => ({
steps: pipeline('steps').map(step => step.merge({
computations: step('computations').map(compId => rethink.table('computations').get(compId)),
})),
}))
.run(connection)
.then(res => connection.close().then(() => res)))
.then(result => result);
}
/**
* Helper function for add permissions to an user
* @param {object} connection - Existing db connection
* @param {object} args - Update object
* @param {string} args.userId - Id of the user which will have permissions changed
* @param {string} args.role - Role of the user
* @param {string} args.doc - Id of the document for which the user will gain access
* @param {string} args.table - Table of the document for which the user will gain access
*/
async function addUserPermissions(connection, args) {
const perms = await rethink.table('users').get(args.userId)('permissions').run(connection);
const { role, doc, table } = args;
let newRoles = [role];
const promises = [];
// Grab existing roles if present
if (perms[table][doc] && perms[table][doc].indexOf(role) === -1) {
newRoles = newRoles.concat(perms[table][doc]);
} else if (perms[table][doc]) {
newRoles = perms[table][doc];
}
const updateObj = { permissions: { [table]: { [doc]: newRoles } } };
// Add entry to user statuses object &&
if (table === 'consortia') {
updateObj.consortiaStatuses = {};
updateObj.consortiaStatuses[doc] = 'none';
promises.push(
rethink.table('consortia').get(doc).update(
{
[`${role}s`]: rethink.row(`${role}s`).append(args.userId),
}
).run(connection)
);
}
promises.push(
rethink.table('users').get(args.userId).update(
updateObj, { returnChanges: true }
).run(connection)
);
return Promise.all(promises);
}
async function removeUserPermissions(connection, args) {
const promises = [];
const nextPermissions = await rethink.table('users')
.get(args.userId)('permissions')(args.table)(args.doc)
.filter(role => role.ne(args.role))
.run(connection);
if (nextPermissions.length === 0) {
const replaceObj = {
permissions: { [args.table]: args.doc },
};
if (args.table === 'consortia') {
replaceObj.consortiaStatuses = args.doc;
await rethink.table('consortia')
.get(args.doc)
.update({ mappedForRun: rethink.row('mappedForRun').difference([args.userId]) })
.run(connection);
}
promises.push(
rethink.table('users').get(args.userId).replace(user => user.without(replaceObj), { nonAtomic: true }).run(connection)
);
} else {
promises.push(
rethink.table('users')
.get(args.userId)
.update({
permissions: {
[args.table]: {
[args.doc]: rethink.row('permissions')(args.table)(args.doc).difference([args.role]),
},
},
}, { nonAtomic: true })
.run(connection)
);
}
if (args.table === 'consortia') {
promises.push(
rethink.table('consortia').get(args.doc).update(
{
[`${args.role}s`]: rethink.row(`${args.role}s`).difference([args.userId]),
}
).run(connection)
);
}
await Promise.all(promises);
}
const pubsub = new PubSub();
initSubscriptions(pubsub);
/* eslint-disable */
const resolvers = {
JSON: GraphQLJSON,
Query: {
/**
* Returns all results.
* @return {array} All results
*/
fetchAllResults: () => fetchAll('runs'),
/**
* Returns single pipeline
* @param {object} args
* @param {string} args.resultId Requested pipeline ID
* @return {object} Requested pipeline if id present, null otherwise
*/
fetchResult: (_, args) => {
if (!args.resultId) {
return null;
} else {
return helperFunctions.getRethinkConnection()
.then(connection =>
rethink.table('runs')
.get(args.resultId)
.run(connection).then(res => connection.close().then(() => res))
)
.then(result => result);
}
},
/**
* Returns all consortia.
* @return {array} All consortia
*/
fetchAllConsortia: () => fetchAll('consortia'),
/**
* Returns single consortium.
* @param {object} args
* @param {string} args.consortiumId Requested consortium ID
* @return {object} Requested consortium if id present, null otherwise
*/
fetchConsortium: (_, args) => args.consortiumId ? fetchOne('consortia', args.consortiumId) : null,
/**
* Returns all computations.
* @return {array} All computations
*/
fetchAllComputations: () => fetchAll('computations'),
/**
* Returns metadata for specific computation name
* @param {object} args
* @param {array} args.computationIds Requested computation ids
* @return {array} List of computation objects
*/
fetchComputation: (_, args) => {
return helperFunctions.getRethinkConnection()
.then((connection) =>
rethink.table('computations').getAll(...args.computationIds)
.run(connection).then(res => connection.close().then(() => res))
)
.then((cursor) => cursor.toArray())
.then((result) => {
return result;
});
},
/**
* Returns all pipelines.
* @return {array} List of all pipelines
*/
fetchAllPipelines: () => {
return helperFunctions.getRethinkConnection()
.then(connection =>
rethink.table('pipelines')
.orderBy({ index: 'id' })
.map(pipeline =>
pipeline.merge(pipeline =>
({
steps: pipeline('steps').map(step =>
step.merge({
computations: step('computations').map(compId =>
rethink.table('computations').get(compId)
)
})
)
})
)
)
.run(connection).then(res => connection.close().then(() => res))
)
.then(cursor => cursor.toArray())
.then(result => result);
},
/**
* Returns single pipeline
* @param {object} args
* @param {string} args.pipelineId Requested pipeline ID
* @return {object} Requested pipeline if id present, null otherwise
*/
fetchPipeline: (_, args) => {
if (!args.pipelineId) {
return null;
} else {
return helperFunctions.getRethinkConnection()
.then(connection =>
rethink.table('pipelines')
.get(args.pipelineId)
// Populate computations subfield with computation meta information
.merge(pipeline =>
({
steps: pipeline('steps').map(step =>
step.merge({
computations: step('computations').map(compId =>
rethink.table('computations').get(compId)
)
})
)
})
)
.run(connection).then(res => connection.close().then(() => res))
)
.then(result => result);
}
},
/**
* Returns single user.
* @param {object} args
* @param {string} args.userId Requested user ID, restricted to authenticated user for time being
* @return {object} Requested user if id present, null otherwise
*/
fetchUser: ({ auth: { credentials } }, args) => {
if (args.userId !== credentials.id) {
return Boom.unauthorized('Unauthorized action');
}
return fetchOne('users', credentials.id);
},
fetchAllUsers: () => fetchAll('users'),
fetchAllUserRuns: ({ auth: { credentials } }, args) => {
let connection;
return helperFunctions.getRethinkConnection()
.then((db) => {
connection = db;
return rethink.table('runs')
.orderBy({ index: 'id' })
.filter(rethink.row('clients').contains(credentials.id))
.run(connection);
}
)
.then(cursor => cursor.toArray())
.then(res => connection.close().then(() => res));
},
validateComputation: (_, args) => {
return new Promise();
},
},
Mutation: {
/**
* Add computation to RethinkDB
* @param {object} args
* @param {object} args.computationSchema Computation object to add/update
* @return {object} New/updated computation object
*/
addComputation: ({ auth: { credentials } }, args) => {
return helperFunctions.getRethinkConnection()
.then((connection) =>
rethink.table('computations').insert(
Object.assign({}, args.computationSchema, { submittedBy: credentials.id }),
{
conflict: "replace",
returnChanges: true,
}
)
.run(connection).then(res => connection.close().then(() => res))
)
.then((result) => {
return result.changes[0].new_val;
})
},
/**
* Add new user role to user perms, currently consortia perms only
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.doc Id of the document to add role to
* @param {string} args.role Role to add to perms
* @param {string} args.userId Id of the user to be added
* @return {object} Updated user object
*/
addUserRole: async ({ auth: { credentials } }, args) => {
const { permissions } = credentials
const documentPermissions = permissions[args.table][args.doc];
if (!documentPermissions || !documentPermissions.includes('owner')) {
return Boom.forbidden('Action not permitted');
}
const connection = await helperFunctions.getRethinkConnection();
await addUserPermissions(connection, args).then(res => connection.close().then(() => res));
return helperFunctions.getUserDetails({ username: args.userId });
},
/**
* Add run to RethinkDB
* @param {String} consortiumId Run object to add/update
* @return {object} New/updated run object
*/
createRun: ({ auth }, { consortiumId }) => {
if (!auth || !auth.credentials) {
// No authorized user, reject
return Boom.unauthorized('User not authenticated');
}
return fetchOne('consortia', consortiumId)
.then(consortium => Promise.all([
consortium,
fetchOnePipeline(consortium.activePipelineId),
helperFunctions.getRethinkConnection()
]))
.then(([consortium, pipelineSnapshot, connection]) =>
rethink.table('runs').insert(
{
clients: [...consortium.members],
consortiumId,
pipelineSnapshot,
startDate: Date.now(),
type: 'decentralized',
},
{
conflict: "replace",
returnChanges: true,
}
)
.run(connection).then(res => connection.close().then(() => res))
)
.then((result) => {
return axios.post(
`http://${config.host}:${config.pipelineServer}/startPipeline`, { run: result.changes[0].new_val }
).then(() => {
return result.changes[0].new_val;
})
})
.catch(error => {
console.log(error)
});
},
/**
* Deletes consortium
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.consortiumId Consortium id to delete
* @return {object} Deleted consortium
*/
deleteConsortiumById: ({ auth: { credentials: { permissions } } }, args) => {
if (!permissions.consortia[args.consortiumId] || !permissions.consortia[args.consortiumId].includes('owner')) {
return Boom.forbidden('Action not permitted');
}
return helperFunctions.getRethinkConnection()
.then(connection =>
new Promise.all([
rethink.table('consortia').get(args.consortiumId)
.delete({ returnChanges: true })
.run(connection),
rethink.table('users').replace(user =>
user.without({
permissions: { consortia: args.consortiumId },
consortiaStatuses: args.consortiumId
})
).run(connection),
rethink.table('pipelines').filter({ owningConsortium: args.consortiumId })
.delete()
.run(connection)
]).then(res => connection.close().then(() => res))
)
.then(([consortium]) => consortium.changes[0].old_val)
},
/**
* Deletes pipeline
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.pipelineId Pipeline id to delete
* @return {object} Deleted pipeline
*/
deletePipeline: async ({ auth: { credentials: { permissions } } }, args) => {
const connection = await helperFunctions.getRethinkConnection()
const pipeline = await rethink.table('pipelines')
.get(args.pipelineId)
.run(connection)
if (!permissions.consortia[pipeline.owningConsortium] ||
!permissions.consortia[pipeline.owningConsortium].includes('owner')
) {
return Boom.forbidden('Action not permitted')
}
const runsCount = await rethink.table('runs')('pipelineSnapshot')
.filter({ id: args.pipelineId })
.count()
.run(connection)
if (runsCount > 0) {
return Boom.badData('Runs on this pipeline exist')
}
await rethink.table('pipelines')
.get(args.pipelineId)
.delete({ returnChanges: true })
.run(connection)
await rethink.table('consortia')
.filter({ activePipelineId: args.pipelineId })
.replace(rethink.row.without('activePipelineId'))
.run(connection)
await connection.close()
return pipeline
},
/**
* Add logged user to consortium members list
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.consortiumId Consortium id to join
* @return {object} Updated consortium
*/
joinConsortium: async ({ auth: { credentials } }, args) => {
const connection = await helperFunctions.getRethinkConnection();
await addUserPermissions(connection, { userId: credentials.id, role: 'member', doc: args.consortiumId, table: 'consortia' })
.then(res => connection.close().then(() => res));
return fetchOne('consortia', args.consortiumId);
},
/**
* Remove logged user from consortium members list
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.consortiumId Consortium id to join
* @return {object} Updated consortium
*/
leaveConsortium: async ({ auth: { credentials } }, args) => {
const connection = await helperFunctions.getRethinkConnection();
await removeUserPermissions(connection, { userId: credentials.id, role: 'member', doc: args.consortiumId, table: 'consortia' })
.then(res => connection.close().then(() => res));
return fetchOne('consortia', args.consortiumId);
},
/**
* Deletes computation
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.computationId Computation id to delete
* @return {object} Deleted computation
*/
removeComputation: ({ auth: { credentials } }, args) => {
return helperFunctions.getRethinkConnection()
.then((connection) =>
new Promise.all([
connection,
rethink.table('computations').get(args.computationId).run(connection)
])
)
.then(([connection, comp]) => {
if (comp.submittedBy !== credentials.id) {
return Boom.forbidden('Action not permitted');
}
return rethink.table('computations').get(args.computationId)
.delete({ returnChanges: true }).run(connection).then(res => connection.close().then(() => res))
})
.then(result => result.changes[0].old_val)
},
/**
* Add new user role to user perms, currently consortia perms only
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.userId Id of the user who will have permissions removed
* @param {string} args.table Table of the document to add role to
* @param {string} args.doc Id of the document to add role to
* @param {string} args.role Role to add to perms
* @param {string} args.userId Id of the user to be removed
* @return {object} Updated user object
*/
removeUserRole: async ({ auth: { credentials } }, args) => {
const { permissions } = credentials
if (!permissions[args.table][args.doc] || !permissions[args.table][args.doc].includes('owner')) {
return Boom.forbidden('Action not permitted');
}
const connection = await helperFunctions.getRethinkConnection();
await removeUserPermissions(connection, args)
.then(res => connection.close().then(() => res));
return helperFunctions.getUserDetails({ username: args.userId });
},
/**
* Sets active pipeline on consortia object
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.consortiumId Consortium to update
* @param {string} args.activePipelineId Pipeline ID to mark as active
*/
saveActivePipeline: async ({ auth: { credentials } }, args) => {
// const { permissions } = credentials;
/* TODO: Add permissions
if (!permissions.consortia.write
&& args.consortium.id
&& !permissions.consortia[args.consortium.id].write) {
return Boom.forbidden('Action not permitted');
}*/
const connection = await helperFunctions.getRethinkConnection()
const result = await rethink.table('consortia')
.get(args.consortiumId)
.update({ activePipelineId: args.activePipelineId, mappedForRun: [] })
.run(connection)
await connection.close()
return result
},
/**
* Saves consortium
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {object} args.consortium Consortium object to add/update
* @return {object} New/updated consortium object
*/
saveConsortium: async ({ auth: { credentials } }, args) => {
const { permissions } = credentials;
const isUpdate = !!args.consortium.id;
if (isUpdate && !permissions.consortia[args.consortium.id].includes('owner')) {
return Boom.forbidden('Action not permitted');
}
const connection = await helperFunctions.getRethinkConnection();
const result = await rethink.table('consortia')
.insert(args.consortium, {
conflict: 'update',
returnChanges: true,
})
.run(connection);
const consortiumId = args.consortium.id || result.changes[0].new_val.id;
if (!isUpdate) {
await addUserPermissions(connection, { userId: credentials.id, role: 'owner', doc: consortiumId, table: 'consortia' });
await addUserPermissions(connection, { userId: credentials.id, role: 'member', doc: consortiumId, table: 'consortia' });
}
const consortium = await fetchOne('consortia', consortiumId);
await connection.close();
return consortium;
},
/**
* Saves run error
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.runId Run id to update
* @param {string} args.error Error
*/
saveError: ({ auth: { credentials } }, args) => {
const { permissions } = credentials;
return helperFunctions.getRethinkConnection()
.then((connection) =>
rethink.table('runs').get(args.runId).update({ error: Object.assign({}, args.error), endDate: Date.now() })
.run(connection).then(res => connection.close()));
// .then(result => result.changes[0].new_val)
},
/**
* Saves pipeline
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {object} args.pipeline Pipeline object to add/update
* @return {object} New/updated pipeline object
*/
savePipeline: async ({ auth: { credentials } }, args) => {
// const { permissions } = credentials;
/* TODO: Add permissions
if (!permissions.consortia.write
&& args.consortium.id
&& !permissions.consortia[args.consortium.id].write) {
return Boom.forbidden('Action not permitted');
}*/
if (args.pipeline && args.pipeline.steps) {
const invalidData = args.pipeline.steps.some(step =>
step.inputMap &&
step.inputMap.covariates &&
step.inputMap.covariates.ownerMappings &&
step.inputMap.covariates.ownerMappings.some(variable =>
!variable.type || !variable.source || !variable.name
)
);
if (invalidData) {
return Boom.badData('Some of the covariates are incomplete');
}
}
const connection = await helperFunctions.getRethinkConnection();
const result = await rethink.table('pipelines')
.insert(args.pipeline, {
conflict: 'update',
returnChanges: true,
})
.run(connection);
const pipelineId = args.pipeline.id || result.changes[0].new_val.id;
const pipeline = await fetchOnePipeline(pipelineId);
await connection.close();
return pipeline;
},
/**
* Saves run results
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.runId Run id to update
* @param {string} args.results Results
*/
saveResults: ({ auth: { credentials } }, args) => {
console.log("save results was called");
const { permissions } = credentials;
return helperFunctions.getRethinkConnection()
.then((connection) =>
rethink.table('runs').get(args.runId).update({ results: Object.assign({}, args.results), endDate: Date.now() })
.run(connection).then(res => connection.close()))
// .then(result => result.changes[0].new_val)
},
setActiveComputation: (_, args) => {
return new Promise();
},
setComputationInputs: (_, args) => {
return new Promise();
},
/**
* Updates run remote state
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.runId Run id to update
* @param {string} args.data State data
*/
updateRunState: ({ auth: { credentials } }, args) => {
const { permissions } = credentials;
return helperFunctions.getRethinkConnection()
.then((connection) => {
return rethink.table('runs').get(args.runId).update({ remotePipelineState: args.data })
.run(connection).then(res => connection.close());
});
// .then(result => result.changes[0].new_val)
},
/**
* Saves consortium
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.consortiumId Consortium id to update
* @param {string} args.status New status
* @return {object} Updated user object
*/
updateUserConsortiumStatus: ({ auth: { credentials } }, { consortiumId, status }) =>
helperFunctions.getRethinkConnection()
.then(connection =>
rethink.table('users')
.get(credentials.id).update({
consortiaStatuses: {
[consortiumId]: status,
},
}).run(connection).then(res => connection.close().then(() => res))
)
.then(result =>
helperFunctions.getUserDetails({ username: credentials.id })
)
.then(result => result)
,
/**
* Updated consortium mapped users
* @param {object} auth User object from JWT middleware validateFunc
* @param {object} args
* @param {string} args.consortiumId Consortium id to update
* @param {string} args.mappedForRun New mappedUsers
* @return {object} Updated user object
*/
updateConsortiumMappedUsers: async ({ auth: { credentials } }, args) => {
const connection = await helperFunctions.getRethinkConnection()
const result = await rethink.table('consortia')
.get(args.consortiumId)
.update({ mappedForRun: args.mappedForRun })
.run(connection)
await connection.close()
return result
}
},
Subscription: {
/**
* Computation subscription
* @param {object} payload
* @param {string} payload.computationId The computation changed
* @param {object} variables
* @param {string} variables.computationId The computation listened for
*/
computationChanged: {
subscribe: withFilter(
() => pubsub.asyncIterator('computationChanged'),
(payload, variables) => (!variables.computationId || payload.computationId === variables.computationId)
)
},
/**
* Consortium subscription
* @param {object} payload
* @param {string} payload.consortiumId The consortium changed
* @param {object} variables
* @param {string} variables.consortiumId The consortium listened for
*/
consortiumChanged: {
subscribe: withFilter(
() => pubsub.asyncIterator('consortiumChanged'),
(payload, variables) => (!variables.consortiumId || payload.consortiumId === variables.consortiumId)
)
},
/**
* Pipeline subscription
* @param {object} payload
* @param {string} payload.pipelineId The pipeline changed
* @param {object} variables
* @param {string} variables.pipelineId The pipeline listened for
*/
pipelineChanged: {
subscribe: withFilter(
() => pubsub.asyncIterator('pipelineChanged'),
(payload, variables) => (!variables.pipelineId || payload.pipelineId === variables.pipelineId)
)
},
/**
* User subscription
* @param {object} payload
* @param {string} payload.userId The user changed
* @param {object} variables
* @param {string} variables.userId The user listened for
*/
userChanged: {
subscribe: withFilter(
() => pubsub.asyncIterator('userChanged'),
(payload, variables) => (variables.userId || payload.userId === variables.userId)
)
},
/**
* User Metadata subscription
* @param {object} payload
* @param {string} payload.userId The user changed
* @param {object} variables
* @param {string} variables.userId The user listened for
*/
userMetadataChanged: {
subscribe: withFilter(
() => pubsub.asyncIterator('userMetadataChanged'),
(payload, variables) => (variables.userId && payload.userId === variables.userId)
)
},
/**
* Run subscription
* @param {object} payload
* @param {string} payload.runId The run changed
* @param {object} variables
* @param {string} variables.userId The user listened for
*/
userRunChanged: {
subscribe: withFilter(
() => pubsub.asyncIterator('userRunChanged'),
(payload, variables) => (variables.userId && payload.userRunChanged.clients.indexOf(variables.userId) > -1)
)
},
},
};
module.exports = {
resolvers,
pubsub,
};