在GraphQL中,"edges"的含义是什么?和“节点"? [英] In GraphQL what's the meaning of "edges" and "node"?

查看:53
本文介绍了在GraphQL中,"edges"的含义是什么?和“节点"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个特定的GraphQL端点,尽管我提供了一个干净的JSON结构作为查询,但是当我得到结果时,我得到了"edges",节点"标签.似乎正在污染我的数据,没有明显的好处.为什么会出现这种情况,并且有可能摆脱这些障碍,以便更快,更简单地解析数据?

I am consuming a particular GraphQL endpoint and although I am supplying a clean JSON structure as a query, when I get the results I get "edges" and "node" tags. It seems as if it is polluting my data with no obvious benefit. Why is it there and is it possible to get rid of those for faster and simpler parsing of data?

推荐答案

让我们从简单的单词开始简短介绍

Let's begin with a short introduction in simple words

GraphQl中继规范

  • 重新获取对象的机制
  • 关于如何通过连接进行分页的说明
  • 围绕突变的结构使其可预测

连接:

  • 连接是带有元数据的对象的集合例如 edges pageInfo ...
  • pageInfo将包含 hasNextPage hasPreviousPage startCursor endCursor

  • hasNextPage 会告诉我们是否还有更多可用的边,或者我们是否已达到此连接的末端.
  • hasNextPage will tell us if there are more edges available, or if we’ve reached the end of this connection.

记录数组:边

  • edges将为您提供使用数据(节点)的灵活性
  • 边缘将帮助您进行分页,有graphql GraphQLList ,但没有分页等功能,仅具有对象(数据)数组
  • edges will provide you flexibility to use your data(node)
  • edges will help you for the pagination, There is graphql GraphQLList but with no functionality such as pagination, only with array of objects (data)

每个边缘都有

  • 节点:记录或数据
  • 一个 cursor :base64编码的字符串,可帮助分页进行中继
  • a node: a record or a data
  • a cursor: base64 encoded string to help relay with pagination

https://facebook.github.io/relay/graphql/connections.htm

节点:

  • 您可以使用中继 connectionArgs(第一个,最后一个,之后,之前)
  • 来设置需要显示的节点数.
  • you can set the number of nodes you need to show using the relay connectionArgs(first, last, after, before)

中继分页的工作原理

  • 获取集合中的所有对象并返回基于 first/last x记录(通过connectionArgs使用的切片)

  • Fetches all objects in the collection and return a slice based on the first/last x records, used thru connectionArgs

之后/之前用于使用来自节点的光标向GraphQL服务器指示所需切片(数据)的数量

after/before are used to indicate to the GraphQL server the number of required slice (data) using cursor from the node

还有更多需要考虑的事情,例如 nodeDefinitions globalFieldId nodeInterfaces

There are many more things to consider like nodeDefinitions, globalFieldId, nodeInterfaces

https://github.com/graphql/graphql-relay-js#对象识别

这篇关于在GraphQL中,"edges"的含义是什么?和“节点"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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