Matt Rider d511d6aa78 Refactor graphql queries
- Remove duplicate queries
- Use smart query in pages/post/_id/_slug/index.vue to avoid multiple db requests for a post and its comments.
We cannot update the apollo cache with asyncData and smart queries have a prefetch policy set to true by default, which
means that they will resolve in a similar timeframe. https://stackoverflow.com/questions/55885337/in-nuxt-should-i-use-asyncdata-or-default-apollo-queries
https://vue-apollo.netlify.com/api/smart-query.html#options
https://vue-apollo.netlify.com/guide/ssr.html#vue-cli-plugin
2019-08-16 11:25:53 +02:00

133 lines
2.6 KiB
JavaScript

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
icon
}
}
tags {
name
}
commentsCount
comments(orderBy: createdAt_asc) {
id
contentExcerpt
content
createdAt
disabled
deleted
author {
id
slug
name
avatar
disabled
deleted
shoutedCount
contributionsCount
commentsCount
followedByCount
followedByCurrentUser
location {
name: name${lang}
}
badges {
id
icon
}
}
}
categories {
id
name
icon
}
shoutedCount
shoutedByCurrentUser
emotionsCount
}
}
`
}
export const filterPosts = i18n => {
const lang = i18n.locale().toUpperCase()
return gql`
query Post($filter: _PostFilter, $first: Int, $offset: Int, $orderBy: [_PostOrdering]) {
Post(filter: $filter, first: $first, offset: $offset, orderBy: $orderBy) {
id
title
contentExcerpt
createdAt
disabled
deleted
slug
image
author {
id
avatar
slug
name
disabled
deleted
contributionsCount
shoutedCount
commentsCount
followedByCount
followedByCurrentUser
location {
name: name${lang}
}
badges {
id
icon
}
}
commentsCount
categories {
id
name
icon
}
shoutedCount
}
}
`
}
export const PostsEmotionsByCurrentUser = () => {
return gql`
query PostsEmotionsByCurrentUser($postId: ID!) {
PostsEmotionsByCurrentUser(postId: $postId)
}
`
}