feat: GraphQL base implementation

This commit is contained in:
NGPixel
2017-07-24 22:37:13 -04:00
parent d76f6182b2
commit 60750eeed8
8 changed files with 118 additions and 20 deletions

67
server/modules/graphql.js Normal file
View File

@@ -0,0 +1,67 @@
'use strict'
/* global wiki */
const gql = require('graphql')
const User = new gql.GraphQLObjectType({
name: 'User',
description: 'A User',
fields() {
return {
id: {
type: gql.GraphQLInt,
resolve(usr) {
return usr.id
}
},
email: {
type: gql.GraphQLString,
resolve(usr) {
return usr.email
}
},
provider: {
type: gql.GraphQLString,
resolve(usr) {
return usr.provider
}
},
providerId: {
type: gql.GraphQLString,
resolve(usr) {
return usr.providerId
}
}
}
}
})
const Query = new gql.GraphQLObjectType({
name: 'Query',
description: 'Root Query',
fields() {
return {
users: {
type: new gql.GraphQLList(User),
args: {
id: {
type: gql.GraphQLInt
},
email: {
type: gql.GraphQLString
}
},
resolve(root, args) {
return wiki.db.User.findAll({ where: args })
}
}
}
}
})
const Schema = new gql.GraphQLSchema({
query: Query
})
module.exports = Schema