roschaefer bb3f419532 Refactor graphql queries and fix bug
It's sometimes unbelievable how many bugs you find when doing
refactoring. This time there was some apparent confusion about
`commentsCount` and `commentedCount`. The counters on the post card were
never showing the correct number.
2019-09-03 21:28:29 +02:00

110 lines
1.7 KiB
JavaScript

import gql from 'graphql-tag'
const fragments = lang => gql`
fragment user on User {
id
slug
name
avatar
disabled
deleted
shoutedCount
contributionsCount
commentedCount
followedByCount
followedByCurrentUser
location {
name: name${lang}
}
badges {
id
icon
}
}
fragment post on Post {
id
title
content
contentExcerpt
createdAt
disabled
deleted
slug
image
commentsCount
shoutedCount
shoutedByCurrentUser
emotionsCount
author {
...user
}
tags {
id
}
categories {
id
name
icon
}
}
`
export default i18n => {
const lang = i18n.locale().toUpperCase()
return gql`
${fragments(lang)}
query Post($id: ID!) {
Post(id: $id) {
...post
comments(orderBy: createdAt_asc) {
id
contentExcerpt
content
createdAt
disabled
deleted
author {
...user
}
}
}
}
`
}
export const filterPosts = i18n => {
const lang = i18n.locale().toUpperCase()
return gql`
${fragments(lang)}
query Post($filter: _PostFilter, $first: Int, $offset: Int, $orderBy: [_PostOrdering]) {
Post(filter: $filter, first: $first, offset: $offset, orderBy: $orderBy) {
...post
}
}
`
}
export const PostsEmotionsByCurrentUser = () => {
return gql`
query PostsEmotionsByCurrentUser($postId: ID!) {
PostsEmotionsByCurrentUser(postId: $postId)
}
`
}
export const relatedContributions = i18n => {
const lang = i18n.locale().toUpperCase()
return gql`
${fragments(lang)}
query Post($slug: String!) {
Post(slug: $slug) {
...post
relatedContributions(first: 2) {
...post
}
}
}
`
}