mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
This is refactoring all our fragments and fixing the warning about an existing name `user`. Apparently, fragments should have a unique name globally. I decided to call `userFragment`, `postFragment` the fragments for one object and use different names to query for related objects. I would be glad to learn a better way to handle this.
143 lines
3.1 KiB
JavaScript
143 lines
3.1 KiB
JavaScript
import gql from 'graphql-tag'
|
|
import {
|
|
userFragment,
|
|
postFragment,
|
|
commentFragment,
|
|
postCountsFragment,
|
|
userCountsFragment,
|
|
locationAndBadgesFragment,
|
|
tagsCategoriesAndPinnedFragment,
|
|
} from './Fragments'
|
|
|
|
export default i18n => {
|
|
const lang = i18n.locale().toUpperCase()
|
|
return gql`
|
|
${userFragment}
|
|
${userCountsFragment}
|
|
${locationAndBadgesFragment(lang)}
|
|
${postFragment}
|
|
${postCountsFragment}
|
|
${tagsCategoriesAndPinnedFragment}
|
|
${commentFragment}
|
|
|
|
query Post($id: ID!) {
|
|
Post(id: $id) {
|
|
...post
|
|
...postCounts
|
|
...tagsCategoriesAndPinned
|
|
author {
|
|
...user
|
|
...userCounts
|
|
...locationAndBadges
|
|
}
|
|
comments(orderBy: createdAt_asc) {
|
|
...comment
|
|
author {
|
|
...user
|
|
...userCounts
|
|
...locationAndBadges
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`
|
|
}
|
|
|
|
export const filterPosts = i18n => {
|
|
const lang = i18n.locale().toUpperCase()
|
|
return gql`
|
|
${userFragment}
|
|
${userCountsFragment}
|
|
${locationAndBadgesFragment(lang)}
|
|
${postFragment}
|
|
${postCountsFragment}
|
|
${tagsCategoriesAndPinnedFragment}
|
|
|
|
query Post($filter: _PostFilter, $first: Int, $offset: Int, $orderBy: [_PostOrdering]) {
|
|
Post(filter: $filter, first: $first, offset: $offset, orderBy: $orderBy) {
|
|
...post
|
|
...postCounts
|
|
...tagsCategoriesAndPinned
|
|
author {
|
|
...user
|
|
...userCounts
|
|
...locationAndBadges
|
|
}
|
|
}
|
|
}
|
|
`
|
|
}
|
|
|
|
export const profilePagePosts = i18n => {
|
|
const lang = i18n.locale().toUpperCase()
|
|
return gql`
|
|
${userFragment}
|
|
${userCountsFragment}
|
|
${locationAndBadgesFragment(lang)}
|
|
${postFragment}
|
|
${postCountsFragment}
|
|
${tagsCategoriesAndPinnedFragment}
|
|
|
|
query profilePagePosts(
|
|
$filter: _PostFilter
|
|
$first: Int
|
|
$offset: Int
|
|
$orderBy: [_PostOrdering]
|
|
) {
|
|
profilePagePosts(filter: $filter, first: $first, offset: $offset, orderBy: $orderBy) {
|
|
...post
|
|
...postCounts
|
|
...tagsCategoriesAndPinned
|
|
author {
|
|
...user
|
|
...userCounts
|
|
...locationAndBadges
|
|
}
|
|
}
|
|
}
|
|
`
|
|
}
|
|
|
|
export const PostsEmotionsByCurrentUser = () => {
|
|
return gql`
|
|
query PostsEmotionsByCurrentUser($postId: ID!) {
|
|
PostsEmotionsByCurrentUser(postId: $postId)
|
|
}
|
|
`
|
|
}
|
|
|
|
export const relatedContributions = i18n => {
|
|
const lang = i18n.locale().toUpperCase()
|
|
return gql`
|
|
${userFragment}
|
|
${userCountsFragment}
|
|
${locationAndBadgesFragment(lang)}
|
|
${postFragment}
|
|
${postCountsFragment}
|
|
${tagsCategoriesAndPinnedFragment}
|
|
|
|
query Post($slug: String!) {
|
|
Post(slug: $slug) {
|
|
...post
|
|
...postCounts
|
|
...tagsCategoriesAndPinned
|
|
author {
|
|
...user
|
|
...userCounts
|
|
...locationAndBadges
|
|
}
|
|
relatedContributions(first: 2) {
|
|
...post
|
|
...postCounts
|
|
...tagsCategoriesAndPinned
|
|
author {
|
|
...user
|
|
...userCounts
|
|
...locationAndBadges
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`
|
|
}
|