Guest User

Untitled

a guest
Nov 30th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. typeError: Cannot read property 'kind' of undefined
  2. at D:Desenvolvimentostatswayadonis-graphql-serverappdataschema.js(anonymous):30
  3. 25 type Schema {
  4. 26 query: Query
  5. 27 mutation: Mutation
  6. 28 }
  7. 30 module.exports = makeExecutableSchema({
  8. 31 typeDefs: [
  9. 32 typeDefs,
  10. 33 Query,
  11. 34 Mutation,
  12. 35 userTypes
  13.  
  14. const userTypes = `
  15. # User definition type
  16. type User {
  17. id: Int!
  18. username: String!
  19. email: String!
  20. posts: [Post]
  21. }
  22. `;
  23.  
  24. const userQueries = `
  25. allUsers: [User]
  26. fetchUser(id: Int!): User
  27. `;
  28.  
  29. const userMutations = `
  30. login (email: String!, password: String!): String
  31. createUser (username: String!, email: String!, password: String!): User
  32. `;
  33.  
  34. module.exports = {
  35. userTypes,
  36. userQueries,
  37. userMutations
  38. }
  39.  
  40. 'use strict'
  41. const User = use('App/Models/User')
  42.  
  43. const userResolver = {
  44. Query: {
  45. async allUsers() {
  46. const users = await User.all()
  47. return users.toJSON()
  48. },
  49. async fetchUser(_, { id }) {
  50. const user = await User.find(id)
  51. return user.toJSON()
  52. }
  53. },
  54. Mutation: {
  55. async login(_, { email, password }, { auth }) {
  56. const { token } = await auth.attempt(email, password)
  57. return token
  58. },
  59.  
  60. async createUser(_, { username, email, password }) {
  61. return await User.create({ username, email, password })
  62. },
  63. },
  64. User: {
  65. async posts(userInJson) {
  66. const user = new User()
  67. user.newUp(userInJson)
  68.  
  69. const posts = await user.posts().fetch()
  70. return posts.toJSON()
  71. }
  72. }
  73. }
  74. module.exports = userResolver;
  75.  
  76. const { userMutations } = require('./user/userSchema');
  77.  
  78. const Mutation = `
  79. type Mutation {
  80. ${userMutations}
  81. }
  82. `;
  83.  
  84. module.exports = Mutation
  85.  
  86. const { userQueries } = require('./user/userSchema');
  87.  
  88. const Query = `
  89. type Query {
  90. ${userQueries}
  91. }
  92. `;
  93.  
  94. module.exports = Query
  95.  
  96. 'use strict'
  97.  
  98. const { makeExecutableSchema } = require('graphql-tools')
  99. const { Query } = require ('./query');
  100. const { Mutation } = require('./mutation');
  101. const { merge } = require ('lodash');
  102.  
  103. const { userTypes } = require ('./user/userSchema');
  104. const { userResolver } = require ('./user/userResolver');
  105.  
  106. const resolvers = merge(
  107. userResolver
  108. )
  109. // Define our schema using the GraphQL schema language
  110. const typeDefs = `
  111. type Schema {
  112. query: Query
  113. mutation: Mutation
  114. }
  115. `
  116. module.exports = makeExecutableSchema({
  117. typeDefs: [
  118. typeDefs,
  119. Query,
  120. Mutation,
  121. userTypes,
  122. ], resolvers })
  123.  
  124. "typescript": "^3.2.1",
Add Comment
Please, Sign In to add comment