I have a root query of songs
, this is in a pagination container.
I then have a nested property on songs called comments
that I also want to be paginated because I don't want to load 10k comments for each song all at once.
songsContainer.js:
fragment songsContainer on Query {
songs(
first: $count
after: $cursor
genre: $genre
filter: $filter
) @connection(key: "songsContainer_songs") {
edges {
node {
audioId
name
coverImageUrl
artist
likes
dislikes
...commentsContainer
}
}
}
}
const connectionConfig = {
direction: 'forward',
query: graphql`
query songsContainerForwardQuery(
$count: Int!
$cursor: String
$genre: String
$filter: FilterInput
) {
...songsContainer
}
`,
getVariables: (_, { count, cursor }) => ({
count,
cursor,
}),
};
paginationContainer(fragments, connectionConfig);
commentsContainer.js
fragment commentsContainer on Audio {
comments(
first: $count
after: $cursor
getReplies: $getReplies
) @connection(key: "commentsContainer_comments") {
edges {
node {
commentId
body
date
likes
dislikes
repliesCount
originalComment {
id
}
user {
userName
}
}
}
}
}
How do I write the connectionConfig for the comments? I tried this:
const connectionConfig = {
direction: 'forward',
query: graphql`
query commentsContainerForwardQuery(
$count: Int!
$cursor: String
) {
...commentsContainer
}
`,
getVariables: (_, { count, cursor }) => ({
count,
cursor,
}),
};
But because the comments are nested on songs then it throws an error saying that the query doesn't exist on the Root.
SongsContainer.js
SongItem.js
CommentsContainer.js