postQuery.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { gql } from "../../helpers/getGQL";
  2. import { actionPromise } from "../types/promiseTypes";
  3. export const actionOnePost = (_id) =>
  4. actionPromise(
  5. 'onePost',
  6. gql(
  7. `query OneFind($post:String){
  8. PostFindOne(query:$post){
  9. _id createdAt title text
  10. images{_id url originalFileName}
  11. comments {
  12. _id createdAt text
  13. likes { _id owner {_id login nick avatar {url} }}
  14. owner {_id login nick
  15. avatar {url}
  16. }
  17. answers{
  18. _id
  19. }
  20. answerTo{_id}
  21. }
  22. likes{
  23. _id
  24. owner{
  25. _id login avatar {url}
  26. }
  27. }
  28. owner {_id login nick
  29. avatar {url}
  30. }
  31. }
  32. }
  33. `,
  34. {
  35. post: JSON.stringify([{ _id }]),
  36. },
  37. ),
  38. )
  39. export const actionPostUpsert = (post, postId) =>
  40. actionPromise(
  41. 'postUpsert',
  42. gql(
  43. `
  44. mutation PostUpsert($post:PostInput){
  45. PostUpsert(post:$post){
  46. _id title text images{_id url}
  47. }
  48. }`,
  49. {
  50. post: {
  51. ...post,
  52. _id:postId,
  53. images: post.images.map(({ _id }) => ({ _id })),
  54. },
  55. },
  56. ),
  57. )