分页:GraphQL 中第一个没有游标的请求?
我认为这里有一些我不明白的地方...第一次在 GraphQL 中使用基于游标的分页。
我在我的 swift 项目中使用 Apollo iOS 客户端。
我似乎无法理解的是,我有一个如下所示的查询:
query BalloonsList {
balloons {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
id
name
description
imageUrl
variant
color
price
availableSince
}
}
}
}
它工作完美,服务器总是响应 5 个对象,并且我收到下一个请求的结束光标。我可以通过在查询中实现一个变量来传递游标,如下所示:
query BalloonsList($cursor:String) {
balloons(after:$cursor) {
但是,当我的查询中有这个变量并且我没有第一个请求的游标时,它会失败。因此,一个选项可能是为第一个请求创建两个不同的查询,一个包含变量,另一个不包含变量,但这似乎是错误的。
我觉得这里有一些基本的东西我不明白?如何仅在第一次获取后在查询中实现 after:
参数?
希望这是有道理的
I think there is something I don't understand here... First time working with cursor-based pagination in GraphQL.
I am using the Apollo iOS client in my swift project.
What I can't seems to grasp is that I have a query that looks like this:
query BalloonsList {
balloons {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
id
name
description
imageUrl
variant
color
price
availableSince
}
}
}
}
It works perfectly, the server always responds with 5 objects and I receive the end-cursor for the next request. I can pass in the cursor by implementing a variable in the query like so:
query BalloonsList($cursor:String) {
balloons(after:$cursor) {
However, when I have this variable in my query and I don't have a cursor for the very first request it fails of cause. So, an option could be to create two different queries one with the variable and one without for the first request, but it just seems wrong.
I feel like there is something fundamental I don't understand here? How do I implement the after:
parameter in my query only after my first fetch?
Hope it makes sense ????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@Herku 是对的。这:
这有效,因为它是可选的。导致问题的原因是 Apollo 为我创建了另一种类型,称为 ID 而不是 String。
@Herku was right. This:
This worked since it's optional. What caused the problem was that Apollo had created another type for me called ID instead of String.