-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
32 lines (29 loc) · 830 Bytes
/
api.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
const { buildSchema } = require('graphql')
// ---------------------------------------------------------------------------
// Schema
// ---------------------------------------------------------------------------
const schema = buildSchema(`
type Query {
greeting: String
rollDice(numDice: Int!, numSides: Int): [Int]
}
`)
// ---------------------------------------------------------------------------
// Resolvers
// ---------------------------------------------------------------------------
const rootValue = {
greeting: function() {
return "Hello World!"
},
rollDice: function ({numDice, numSides}) {
const output = []
for (var i = 0; i < numDice; i++) {
output.push(1 + Math.floor(Math.random() * (numSides || 6)))
}
return output
}
};
module.exports = {
schema,
rootValue
}