【发布时间】:2021-09-09 13:00:12
【问题描述】:
美好的一天。我在前端使用 gatsby,在后端使用 strapi。我正在尝试制作一个带有简单分页的媒体库,以便为自定义组件选择图像。
我获取图像并使用此查询
query MyQuery($currentPage: Int!) {
allStrapiMedia(limit: 20,currentPage:$currentPage ) {
edges {
node {
name
}
}
pageInfo {
itemCount
hasNextPage
pageCount
currentPage
perPage
totalCount
hasPreviousPage
}
}
}
但我收到此错误:
{
"errors": [
{
"message": "Unknown argument \"currentPage\" on field \"Query.allStrapiMedia\".",
"locations": [
{
"line": 2,
"column": 28
}
],
"stack": [
"GraphQLError: Unknown argument \"currentPage\" on field \"Query.allStrapiMedia\".",
" at Object.Argument (/Users/alexeigarban/Documents/projects/platformable/platformablecodegenerator copy/node_modules/graphql/validation/rules/KnownArgumentNamesRule.js:46:29)",
" at Object.enter (/Users/alexeigarban/Documents/projects/platformable/platformablecodegenerator copy/node_modules/graphql/language/visitor.js:323:29)",
" at Object.enter (/Users/alexeigarban/Documents/projects/platformable/platformablecodegenerator copy/node_modules/graphql/utilities/TypeInfo.js:370:25)",
" at visit (/Users/alexeigarban/Documents/projects/platformable/platformablecodegenerator copy/node_modules/graphql/language/visitor.js:243:26)",
" at validate (/Users/alexeigarban/Documents/projects/platformable/platformablecodegenerator copy/node_modules/graphql/validation/validate.js:69:24)",
" at /Users/alexeigarban/Documents/projects/platformable/platformablecodegenerator copy/node_modules/express-graphql/index.js:121:32",
" at processTicksAndRejections (internal/process/task_queues.js:95:5)"
]
}
],
"extensions": {}
}
如果我删除 currentPage var 它可以工作,但我无法转到 currentPage:2 ,...+,这意味着我只能看到前 20 个。
我错过了什么?
感谢您的宝贵时间
【问题讨论】:
-
使用 playground 来检查 args ...使用
start: (currentPage - 1) * perPage? -
感谢您的回复,我应该在这里使用它吗:allStrapiMedia(limit: 20,currentPage:$currentPage): 我没有“开始”,只是限制、跳过和排序),
-
.......尝试跳过?
标签: reactjs pagination graphql gatsby