Centralized and refactored report mutations and queries

This commit is contained in:
Wolfgang Huß 2019-10-04 10:40:18 +02:00
parent e7fbd169d9
commit b4f47997b3
3 changed files with 17 additions and 12 deletions

View File

@ -68,8 +68,8 @@
</template> </template>
<script> <script>
import gql from 'graphql-tag'
import { SweetalertIcon } from 'vue-sweetalert-icons' import { SweetalertIcon } from 'vue-sweetalert-icons'
import { reportMutation } from '~/graphql/Moderation.js'
export default { export default {
name: 'ReportModal', name: 'ReportModal',
@ -173,13 +173,7 @@ export default {
// await this.modalData.buttons.confirm.callback() // await this.modalData.buttons.confirm.callback()
this.$apollo this.$apollo
.mutate({ .mutate({
mutation: gql` mutation: reportMutation(),
mutation($id: ID!, $reasonCategory: String!, $description: String!) {
report(id: $id, reasonCategory: $reasonCategory, description: $description) {
id
}
}
`,
variables: { variables: {
id: this.id, id: this.id,
reasonCategory: reasonCategory.value, reasonCategory: reasonCategory.value,

View File

@ -1,13 +1,14 @@
import gql from 'graphql-tag' import gql from 'graphql-tag'
export default app => { export const reportListQuery = () => {
return gql` return gql`
query { query {
Report(first: 20, orderBy: createdAt_desc) { Report(first: 20, orderBy: createdAt_desc) {
id id
createdAt
reasonCategory
description description
type type
createdAt
submitter { submitter {
id id
slug slug
@ -79,3 +80,13 @@ export default app => {
} }
` `
} }
export const reportMutation = () => {
return gql`
mutation($id: ID!, $reasonCategory: String!, $description: String!) {
report(id: $id, reasonCategory: $reasonCategory, description: $description) {
id
}
}
`
}

View File

@ -110,7 +110,7 @@
<script> <script>
import HcEmpty from '~/components/Empty.vue' import HcEmpty from '~/components/Empty.vue'
import query from '~/graphql/ModerationListQuery.js' import { reportListQuery } from '~/graphql/Moderation.js'
export default { export default {
components: { components: {
@ -134,7 +134,7 @@ export default {
}, },
apollo: { apollo: {
Report: { Report: {
query, query: reportListQuery(),
fetchPolicy: 'cache-and-network', fetchPolicy: 'cache-and-network',
}, },
}, },