You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wiki/server/modules/graphql.js

68 lines
1.2 KiB

'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