postQuery.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 createdAt text
  19. owner {_id login nick
  20. avatar {url}
  21. }
  22. }
  23. answerTo{_id
  24. createdAt text
  25. owner {_id login nick
  26. avatar {url}
  27. }
  28. }
  29. }
  30. likes{
  31. _id
  32. owner{
  33. _id login avatar {url}
  34. }
  35. }
  36. owner {_id login nick
  37. avatar {url}
  38. }
  39. }
  40. }
  41. `,
  42. {
  43. post: JSON.stringify([{ _id }]),
  44. },
  45. ),
  46. )
  47. export const actionPostUpsert = (post, postId) =>
  48. actionPromise(
  49. 'postUpsert',
  50. gql(
  51. `
  52. mutation PostUpsert($post:PostInput){
  53. PostUpsert(post:$post){
  54. _id title text images{_id url
  55. originalFileName
  56. }
  57. }
  58. }`,
  59. {
  60. post: {
  61. ...post,
  62. _id: postId,
  63. images: post.images.map(({ _id }) => ({ _id })),
  64. },
  65. },
  66. ),
  67. )