GitHub 如何对其 graphQL 游标进行编码?
GitHub 的 graphql 游标故意是不透明的,因此客户端不应该对其进行解码。不过我想知道他们的分页方法,特别是与排序结合使用时。
GitHub's graphql cursors are intentionally opaque, so they shouldn't ever be decode by a client. However I'd like to know their approach towards pagination, especially when combined with sorting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GitHub 使用的分页游标的编码有多层编码。我将从解码器的角度按顺序列出它们:
-
和_
而不是+
和/
。这可能是为了与基于 REST 的 API 保持一致。cursor:v2:[something]
的字符串,因此下一步是解码该东西。0x91
=>我们不使用任何排序,游标包含id字段的长度和id本身。0xcd
似乎表示一个两字节的 id,0xce
表示一个四字节的 id。接下来是 id 本身,可以通过解码 base64id
graphql 字段来验证。0x92
=>包含已排序属性和 id 的复合游标。它可以是一个长度前缀的序数,也可以是两个字节加上一个字符串或 ISO 日期字符串,后跟长度前缀的 id。There are multiple layers of encoding for the encoding used for pagination cursors used by GitHub. I will list them in order from the perspective of a decoder:
-
and_
instead of+
and/
. This might be to have consistency with their REST based API.cursor:v2:[something]
so the next step is decoding the something.0x91
=> We don't use any sorting, the cursor contains the length of the id field and the id itself.0xcd
seems to indicate a two-byte id,0xce
a four-byte id. This is followed by the id itself, which can be verified by decoding the base64id
graphql field.0x92
=> A composite cursor containing the sorted property and the id. This is either a length-prefixed ordinal number or two bytes plus a string or ISO date string followed by the length-prefixed id.