GitHub 如何对其 graphQL 游标进行编码?

发布于 2025-01-16 12:14:18 字数 75 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人九事 2025-01-23 12:14:18

GitHub 使用的分页游标的编码有多层编码。我将从解码器的角度按顺序列出它们:

  1. 光标字符串使用 URL安全base64意味着它使用-_而不是+/。这可能是为了与基于 REST 的 API 保持一致。
  2. 解码 Base64 字符串会得到另一个格式为 cursor:v2:[something] 的字符串,因此下一步是解码该东西。
  3. “某物”是包含实际光标属性的二进制编码数据。第一个字节定义游标类型:
    • 0x91 =>我们不使用任何排序,游标包含id字段的长度和id本身。 0xcd 似乎表示一个两字节的 id,0xce 表示一个四字节的 id。接下来是 id 本身,可以通过解码 base64 id 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:

  1. The cursor string is encoded using URL safe base64 meaning it uses - and _ instead of + and /. This might be to have consistency with their REST based API.
  2. Decoding the base64 string gives us another string in the format of cursor:v2:[something] so the next step is decoding the something.
  3. The 'something' is a binary encoded piece of data containing the actual cursor properties. The first byte defines the cursor type:
    • 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 base64 id 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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文