mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Refactor code to extract query to it's own file
This commit is contained in:
parent
db3221cec6
commit
1c1a390d0c
79
webapp/graphql/PostQuery.js
Normal file
79
webapp/graphql/PostQuery.js
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import gql from 'graphql-tag'
|
||||||
|
|
||||||
|
export default i18n => {
|
||||||
|
const lang = i18n.locale().toUpperCase()
|
||||||
|
return gql(`
|
||||||
|
query Post($slug: String!) {
|
||||||
|
Post(slug: $slug) {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
content
|
||||||
|
createdAt
|
||||||
|
disabled
|
||||||
|
deleted
|
||||||
|
slug
|
||||||
|
image
|
||||||
|
author {
|
||||||
|
id
|
||||||
|
slug
|
||||||
|
name
|
||||||
|
avatar
|
||||||
|
disabled
|
||||||
|
deleted
|
||||||
|
shoutedCount
|
||||||
|
contributionsCount
|
||||||
|
commentsCount
|
||||||
|
followedByCount
|
||||||
|
followedByCurrentUser
|
||||||
|
location {
|
||||||
|
name: name${lang}
|
||||||
|
}
|
||||||
|
badges {
|
||||||
|
id
|
||||||
|
key
|
||||||
|
icon
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tags {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
commentsCount
|
||||||
|
comments(orderBy: createdAt_desc) {
|
||||||
|
id
|
||||||
|
contentExcerpt
|
||||||
|
createdAt
|
||||||
|
disabled
|
||||||
|
deleted
|
||||||
|
author {
|
||||||
|
id
|
||||||
|
slug
|
||||||
|
name
|
||||||
|
avatar
|
||||||
|
disabled
|
||||||
|
deleted
|
||||||
|
shoutedCount
|
||||||
|
contributionsCount
|
||||||
|
commentsCount
|
||||||
|
followedByCount
|
||||||
|
followedByCurrentUser
|
||||||
|
location {
|
||||||
|
name: name${lang}
|
||||||
|
}
|
||||||
|
badges {
|
||||||
|
id
|
||||||
|
key
|
||||||
|
icon
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
categories {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
icon
|
||||||
|
}
|
||||||
|
shoutedCount
|
||||||
|
shoutedByCurrentUser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
@ -62,8 +62,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import gql from 'graphql-tag'
|
|
||||||
|
|
||||||
import HcCategory from '~/components/Category'
|
import HcCategory from '~/components/Category'
|
||||||
import HcTag from '~/components/Tag'
|
import HcTag from '~/components/Tag'
|
||||||
import ContentMenu from '~/components/ContentMenu'
|
import ContentMenu from '~/components/ContentMenu'
|
||||||
@ -72,6 +70,7 @@ import HcShoutButton from '~/components/ShoutButton.vue'
|
|||||||
import HcCommentForm from '~/components/comments/CommentForm'
|
import HcCommentForm from '~/components/comments/CommentForm'
|
||||||
import HcCommentList from '~/components/comments/CommentList'
|
import HcCommentList from '~/components/comments/CommentList'
|
||||||
import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostHelpers'
|
import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostHelpers'
|
||||||
|
import PostQuery from '~/graphql/PostQuery.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'PostSlug',
|
name: 'PostSlug',
|
||||||
@ -113,80 +112,7 @@ export default {
|
|||||||
app: { apolloProvider, $i18n },
|
app: { apolloProvider, $i18n },
|
||||||
} = context
|
} = context
|
||||||
const client = apolloProvider.defaultClient
|
const client = apolloProvider.defaultClient
|
||||||
const query = gql(`
|
const query = PostQuery($i18n)
|
||||||
query Post($slug: String!) {
|
|
||||||
Post(slug: $slug) {
|
|
||||||
id
|
|
||||||
title
|
|
||||||
content
|
|
||||||
createdAt
|
|
||||||
disabled
|
|
||||||
deleted
|
|
||||||
slug
|
|
||||||
image
|
|
||||||
author {
|
|
||||||
id
|
|
||||||
slug
|
|
||||||
name
|
|
||||||
avatar
|
|
||||||
disabled
|
|
||||||
deleted
|
|
||||||
shoutedCount
|
|
||||||
contributionsCount
|
|
||||||
commentsCount
|
|
||||||
followedByCount
|
|
||||||
followedByCurrentUser
|
|
||||||
location {
|
|
||||||
name: name${$i18n.locale().toUpperCase()}
|
|
||||||
}
|
|
||||||
badges {
|
|
||||||
id
|
|
||||||
key
|
|
||||||
icon
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tags {
|
|
||||||
name
|
|
||||||
}
|
|
||||||
commentsCount
|
|
||||||
comments(orderBy: createdAt_desc) {
|
|
||||||
id
|
|
||||||
contentExcerpt
|
|
||||||
createdAt
|
|
||||||
disabled
|
|
||||||
deleted
|
|
||||||
author {
|
|
||||||
id
|
|
||||||
slug
|
|
||||||
name
|
|
||||||
avatar
|
|
||||||
disabled
|
|
||||||
deleted
|
|
||||||
shoutedCount
|
|
||||||
contributionsCount
|
|
||||||
commentsCount
|
|
||||||
followedByCount
|
|
||||||
followedByCurrentUser
|
|
||||||
location {
|
|
||||||
name: name${$i18n.locale().toUpperCase()}
|
|
||||||
}
|
|
||||||
badges {
|
|
||||||
id
|
|
||||||
key
|
|
||||||
icon
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
categories {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
icon
|
|
||||||
}
|
|
||||||
shoutedCount
|
|
||||||
shoutedByCurrentUser
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
const variables = { slug: params.slug }
|
const variables = { slug: params.slug }
|
||||||
const {
|
const {
|
||||||
data: { Post },
|
data: { Post },
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user