-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetListQueryConfig.js
More file actions
56 lines (55 loc) · 1.65 KB
/
Copy pathgetListQueryConfig.js
File metadata and controls
56 lines (55 loc) · 1.65 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 {
GraphQLObjectType,
GraphQLList,
GraphQLInt,
key
} from './'
import plural from 'plural'
/**
*
* @param {GraphQLObjectType} ObjectType
* @param {Function} resolve resolve function
* @param {Object} options Options
* @param {Object} options.fields more fields to append to fields
* @param {Object} options.args more argements to append to args
*/
export default function getQueryConfig(ObjectType, resolve, options = {fields: {}, args: {}}) {
return {
[key(ObjectType.pluralName || plural(ObjectType.name))] : {
type: new GraphQLObjectType({
name: ObjectType.pluralName || plural(ObjectType.name),
fields: Object.assign(
{
list: {
type: new GraphQLList(ObjectType)
},
total: {
type: GraphQLInt
},
page: {
type: GraphQLInt
},
limit: {
type: GraphQLInt
}
},
options.fields || {}
)
}),
args: Object.assign(
{
page: {
type: GraphQLInt,
defaultValue: 1
},
limit: {
type: GraphQLInt,
defaultValue: 20
}
},
options.args || {}
),
resolve
}
}
}