我有一个根查询songs
,它位于分页容器中。然后,我在歌曲上有一个嵌套属性,称为comments
我也想分页,因为我不想一次为每首歌曲加载 10k 条评论。
歌曲容器.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);
评论容器.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
}
}
}
}
}
如何为评论编写 connectionConfig?我试过这个:
const connectionConfig = {
direction: 'forward',
query: graphql`
query commentsContainerForwardQuery(
$count: Int!
$cursor: String
) {
...commentsContainer
}
`,
getVariables: (_, { count, cursor }) => ({
count,
cursor,
}),
};
但是因为评论嵌套在歌曲上,所以它会抛出一个错误,指出查询在根目录上不存在。