Advertisement
Guest User

Untitled

a guest
Apr 29th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. //-----types.graphql
  2.  
  3. type Post {
  4. id: Int
  5. user_id: Int
  6. title: String
  7. description: String
  8. created_at: Date
  9. updated_at: Date
  10. }
  11.  
  12. type User {
  13. id: Int
  14. username: String
  15. password: String
  16. created_at: Date
  17. updated_at: Date
  18. }
  19.  
  20. type Query {
  21. users: [User]
  22. user(id: Int!): User
  23. posts: [Post]
  24. post(id: Int!): Int
  25. }
  26.  
  27. //------resolver.js
  28.  
  29. const resolvers = {
  30. ...
  31. async users() {
  32. const users = await User.all()
  33. return users.toJSON()
  34. },
  35. // Get a user by its ID
  36. async user(_, { id }) {
  37. const user = await User.find(id)
  38. return user.toJSON()
  39. }
  40. async posts() {
  41. const posts = await Post.all()
  42. return posts.toJSON()
  43. },
  44. // Get a user by its ID
  45. async post(_, { id }) {
  46. const post = await Post.find(id)
  47. return post.toJSON()
  48. }
  49. ...
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement