连接中的不透明游标是否应该在不同的字段参数中保持稳定?

Should the opaque cursors in connections be stable across different field args?

RANGE_ADD 突变需要 edgeName 以便它可以将新边插入到客户端连接中。作为其查询的一部分,它还包括 cursor.

问题是服务器无法知道客户端在生成边缘响应时可能将哪些参数应用于连接。

这是否意味着 cursor 应该是稳定的?

一般来说,当连接使用不同的参数时,游标不需要相同。例如,如果我这样做了:

{
  namedFriends: friends(orderby:NAME first:5) {
    edges { cursor, node { id } }
  }
  favoriteFriends: friends(orderby:FAVORITE first:5) {
    edges { cursor, node { id } }
  }
}

不同的后端可能用于为这两个连接提供服务,因为我们可能对这两个排序有不同的后端;因此,同一个朋友的游标可能不同,因为他们可能需要为不同的后端编码不同的信息。

这使得执行突变时变得棘手,但是:

mutation M {
  addFriend($input) {
    newFriendsEdge {
      { cursor, node { id } } // Which cursor is this?
    }
  }
}

在这种情况下,突变将 return 来自连接的边缘, 字段 接受相同的非分页参数很有用连接确实如此。所以在上面的例子中,我们会做:

mutation M {
  addFriend($input) {
    newNamedFriendsEdge: newFriendsEdge(orderby:NAME) {
      { cursor, node { id } } // Cursor for namedFriends
    }
    newFavoriteFriendsEdge: newFriendsEdge(orderby:FAVORITE) {
      { cursor, node { id } } // Cursor for favoriteFriends
    }
  }
}

理想情况下,newFriendsEdge(orderby:FAVORITE)favoriteFriends: friends(orderby:FAVORITE first:5) 的实现共享通用代码来生成游标。

请注意,虽然游标不需要相同,但作为服务器的实现细节,如果它们相同也没关系。通常,游标只是节点的 ID,这是发生这种情况的常见方式。实际上,在这些情况下,如果连接上的参数 不会 影响游标,我们会从突变的边缘字段中忽略它;所以如果 orderby 没有影响光标,那么:

mutation M {
  addFriend($input) {
    newFriendsEdge {
      { cursor, node { id } } // orderby didn't exist on newFriendsEdge, so this cursor must apply to both.
    }
  }
}

这是我们突变中的常见模式。如果您 运行 遇到任何问题,请告诉我;我们在开发 returning edges on mutations 的模式时仔细考虑了 "arguments change cursors" 案例,以确保有一个可能的解决方案(这是我们提出关于边缘字段想法的论点),但它并没有在实践中出现那么多,所以如果你 运行 一定要让我知道,我们可以而且应该重新审视这些假设/要求!