Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphql 什么';顶级边和顶级节点之间的区别是什么?_Graphql - Fatal编程技术网

Graphql 什么';顶级边和顶级节点之间的区别是什么?

Graphql 什么';顶级边和顶级节点之间的区别是什么?,graphql,Graphql,我是GraphQL新手,正在使用WPGraphQL和WooGraphQL 它们的顶级连接允许我扩展节点和边,如下所示: { wpgraphql { productCategories { # What's the difference between these? # 1) top-level nodes nodes { id name } # 2) top-level edges

我是GraphQL新手,正在使用WPGraphQL和WooGraphQL

它们的顶级连接允许我扩展
节点
,如下所示:

{
  wpgraphql {
    productCategories {
      # What's the difference between these?

      # 1) top-level nodes
      nodes {
        id
        name
      }

      # 2) top-level edges
      edges {
        node {
          id
          name
        }
      }
    }
  }
}
返回如下响应(省略ID):


我的问题很简单:我用哪一个?为什么两者都有?

这里是GraphiQL资源管理器的屏幕截图,如果有帮助的话


实现类型的GraphQL模式利用类型为一对多或多对多关系建模

每个连接都包括一个边列表和一个
PageInfo
对象。每个边包括一个
节点和该节点的
光标

边缘还可能包含其他字段——例如,如果用户节点之间有一个friends连接,则可能包含创建友谊时的时间戳。但是,通常情况下,边仅用于它们所暴露的
光标
字段。在通过连接分页时使用
光标
值,并为每个边公开它意味着您可以从结果中的任意点开始分页。游标不作为节点的一部分包含,因为它可能特定于连接,而不仅仅是节点本身(例如,某些游标编码排序条件)

但是,如果作为客户机,您不需要对连接结果进行分页,只需要获取所有节点,那么您可能不关心游标。在这些场景中,拥有边不会增加任何价值,只会增加查询的深度。因此,为了方便客户端,一些GraphQL服务选择只公开连接的节点和边缘

{
  "data": {
    "wpgraphql": {
      "productCategories": {
        "nodes": [
          {
            "name": "Accessories"
          },
          {
            "name": "Gift Cards"
          },
          {
            "name": "Indoor"
          }
        ],
        "edges": [
          {
            "node": {
              "name": "Accessories"
            }
          },
          {
            "node": {
              "name": "Gift Cards"
            }
          },
          {
            "node": {
              "name": "Indoor"
            }
          }
        ]
      }
    }
  }
}