mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
@mattwr18 I prefer (I believe it's even best practice) that a delete
mutation should return the deleted object. If you run the delete
mutation again, it should return `null` because there is no object like
that anymore. That way the client knows if a delete mutation has changed
any state in the database.
Also I fixed another bug in the resolver. If your graphql mutation looks
like this:
```gql
mutation {
RemovePostEmotions(to:{ id:"p15"}, data:{emotion: angry}) {
from {
id
name
}
to {
id
title
}
emotion
}
}
```
Then you get errors because your resolver does not return the name for
the user or the title for the post anymore. Just use spread operator...
and it's fixed.
91 lines
1.7 KiB
JavaScript
91 lines
1.7 KiB
JavaScript
import gql from 'graphql-tag'
|
|
|
|
export default () => {
|
|
return {
|
|
CreatePost: gql`
|
|
mutation(
|
|
$title: String!
|
|
$content: String!
|
|
$language: String
|
|
$categoryIds: [ID]
|
|
$imageUpload: Upload
|
|
) {
|
|
CreatePost(
|
|
title: $title
|
|
content: $content
|
|
language: $language
|
|
categoryIds: $categoryIds
|
|
imageUpload: $imageUpload
|
|
) {
|
|
title
|
|
slug
|
|
content
|
|
contentExcerpt
|
|
language
|
|
}
|
|
}
|
|
`,
|
|
UpdatePost: gql`
|
|
mutation(
|
|
$id: ID!
|
|
$title: String!
|
|
$content: String!
|
|
$language: String
|
|
$imageUpload: Upload
|
|
$categoryIds: [ID]
|
|
$image: String
|
|
) {
|
|
UpdatePost(
|
|
id: $id
|
|
title: $title
|
|
content: $content
|
|
language: $language
|
|
imageUpload: $imageUpload
|
|
categoryIds: $categoryIds
|
|
image: $image
|
|
) {
|
|
id
|
|
title
|
|
slug
|
|
content
|
|
contentExcerpt
|
|
language
|
|
}
|
|
}
|
|
`,
|
|
DeletePost: gql`
|
|
mutation($id: ID!) {
|
|
DeletePost(id: $id) {
|
|
id
|
|
}
|
|
}
|
|
`,
|
|
AddPostEmotionsMutation: gql`
|
|
mutation($to: _PostInput!, $data: _EMOTEDInput!) {
|
|
AddPostEmotions(to: $to, data: $data) {
|
|
emotion
|
|
from {
|
|
id
|
|
}
|
|
to {
|
|
id
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
RemovePostEmotionsMutation: gql`
|
|
mutation($to: _PostInput!, $data: _EMOTEDInput!) {
|
|
RemovePostEmotions(to: $to, data: $data) {
|
|
emotion
|
|
from {
|
|
id
|
|
}
|
|
to {
|
|
id
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
}
|
|
}
|