graphql.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict'
  2. /* global wiki */
  3. const gql = require('graphql')
  4. const User = new gql.GraphQLObjectType({
  5. name: 'User',
  6. description: 'A User',
  7. fields() {
  8. return {
  9. id: {
  10. type: gql.GraphQLInt,
  11. resolve(usr) {
  12. return usr.id
  13. }
  14. },
  15. email: {
  16. type: gql.GraphQLString,
  17. resolve(usr) {
  18. return usr.email
  19. }
  20. },
  21. provider: {
  22. type: gql.GraphQLString,
  23. resolve(usr) {
  24. return usr.provider
  25. }
  26. },
  27. providerId: {
  28. type: gql.GraphQLString,
  29. resolve(usr) {
  30. return usr.providerId
  31. }
  32. }
  33. }
  34. }
  35. })
  36. const Query = new gql.GraphQLObjectType({
  37. name: 'Query',
  38. description: 'Root Query',
  39. fields() {
  40. return {
  41. users: {
  42. type: new gql.GraphQLList(User),
  43. args: {
  44. id: {
  45. type: gql.GraphQLInt
  46. },
  47. email: {
  48. type: gql.GraphQLString
  49. }
  50. },
  51. resolve(root, args) {
  52. return wiki.db.User.findAll({ where: args })
  53. }
  54. }
  55. }
  56. }
  57. })
  58. const Schema = new gql.GraphQLSchema({
  59. query: Query
  60. })
  61. module.exports = Schema