-
-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathWebhookCollection.js
More file actions
56 lines (47 loc) · 1.54 KB
/
WebhookCollection.js
File metadata and controls
56 lines (47 loc) · 1.54 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { GraphQLList, GraphQLNonNull, GraphQLObjectType } from 'graphql';
import models from '../../../models';
import { fetchAccountWithReference, GraphQLAccountReferenceInput } from '../input/AccountReferenceInput';
import { CollectionArgs, CollectionFields, GraphQLCollection } from '../interface/Collection';
import { GraphQLWebhook } from '../object/Webhook';
export const GraphQLWebhookCollection = new GraphQLObjectType({
name: 'WebhookCollection',
interfaces: [GraphQLCollection],
description: 'A collection of webhooks',
fields: () => {
return {
...CollectionFields,
nodes: {
type: new GraphQLList(GraphQLWebhook),
},
};
},
});
export const WebhookCollectionArgs = {
limit: CollectionArgs.limit,
offset: CollectionArgs.offset,
account: { type: new GraphQLNonNull(GraphQLAccountReferenceInput) },
};
export const WebhookCollectionResolver = async (args, req) => {
// Check Pagination arguments
if (args.limit <= 0) {
args.limit = CollectionArgs.limit.defaultValue;
}
if (args.offset <= 0) {
args.offset = CollectionArgs.offset.defaultValue;
}
// Check and Fetch account
const account = await fetchAccountWithReference(args.account, { loaders: req.loaders, throwIfMissing: true });
const where = { CollectiveId: account.id };
const { offset, limit } = args;
const result = await models.ActivitySubscription.findAndCountAll({
where,
limit,
offset,
});
return {
nodes: result.rows,
totalCount: result.count,
limit: args.limit,
offset: args.offset,
};
};