什么时候应该使用Relay GraphQL连接以及何时使用普通列表? [英] When should I use a Relay GraphQL connection and when a plain list?

查看:46
本文介绍了什么时候应该使用Relay GraphQL连接以及何时使用普通列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Relay GraphQL中,连接和列表都类似于数组,但是它们具有不同的功能.我应该何时使用它们?

In Relay GraphQL, connections and lists are both array-like, but they have different features. When should I use each?

推荐答案

连接

  • 比简单列表更强大,更灵活.
  • 通过光标支持分页(向前和向后).
  • 细粒度的变异支持(例如, RANGE_ADD RANGE_DELETE NODE_DELETE ,如指南).
  • 需要 first last 参数,以限制结果集的大小.
  • 具有一个 edges 字段,该字段为查找每个边缘,特定于边缘的数据提供了一个位置.
  • 一个较重的概念,需要更多的工作才能在模式中定义.
  • Connections

    • More powerful and flexible than simple lists.
    • Support pagination (forward and back), with cursors.
    • Fine-grained mutation support (eg. RANGE_ADD, RANGE_DELETE, NODE_DELETE, as described in the guide).
    • Requires a first or last argument in order to limit the size of the result set.
    • Has an edges field that provides a place to locate per-edge, edge-specific data.
    • A heavier-weight concept, requiring more work to define in the schema.
      • 简单轻巧.
      • 不支持分页(始终返回整个列表).
      • 没有特殊的突变功能可进行添加,添加等操作(尽管它是必需的功能).
      • 每当需要分页时,都应使用连接.
      • 如果您需要对突变进行细粒度的控制,即使您不需要分页,也可以选择使用连接.
      • 如果要连接中的所有项目,则可以先大量使用 first .
      • 如果要以最小的努力公开简短列表,请使用简单列表.

      这篇关于什么时候应该使用Relay GraphQL连接以及何时使用普通列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆