-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.js
50 lines (46 loc) · 1.06 KB
/
schema.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
// this is an example of what a manually(sans graphql-tools) created graphql scheme looks like
// graphql-tools custom syntax is shorter and contains less noise
'use strict';
const {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLID,
GraphQLNonNull
} = require('graphql');
const { getCount, incrementCount } = require('./methods');
const userId = {
name: 'user',
type: new GraphQLNonNull(GraphQLID),
required: true
};
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
count: {
type: GraphQLInt,
args: {
user: userId
},
resolve: (parent, { user }) => getCount(user)
}
}
}),
mutation: new GraphQLObjectType({
name: 'RootMutationType',
fields: {
incrementCount: {
args: {
user: userId,
n: { name: 'n', type: GraphQLInt }
},
type: GraphQLInt,
resolve: (parent, { user, n }) => incrementCount(user, n)
}
}
})
});
module.exports = schema;