GraphQL 查询访问数组中的第一项? [英] GraphQL query to access first item in an array?

查看:20
本文介绍了GraphQL 查询访问数组中的第一项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进行了很好的搜索,但似乎找不到任何相关内容.GraphQL 有没有办法只访问数组中的第一项?

Had a good search, but can't seem to find anything for this. Is there a way in GraphQL to only access the first item in an array?

类似于:

query {
  allDBItems {
    edges {
      node {
        exampleArray([0])
      }
    }
  }
}

推荐答案

不,GraphQL 不提供任何用于操作请求的语法,除了使用 @skip 和 <代码>@include 指令.

No, GraphQL does not provide any syntax for manipulating the request, outside of conditionally including/excluding fields using the @skip and @include directives.

您正在查询的 GraphQL 服务可能支持通过在字段上提供参数(如 limitfirstlast.但是,由服务器将这些字段包含为服务模式的一部分并提供实现它们的逻辑.查看您的 API 文档以了解这些字段是否受支持.

The GraphQL service you are querying may support a way to limit the result set for a field to a specific length by providing an argument on the field like limit, first or last. However, it's up to the server to include these fields as part of the service's schema and to provide the logic to implement them. Check your API's documentation to see if these fields are supported.

对响应的任何操作都必须在客户端完成.有一个实验性的 graphql-lodash 库可以让你做这就在您的查询中——但归根结底,数据仍在客户端进行转换.

Any manipulations of the response have to be done client-side. There is an experimental graphql-lodash library that lets you do this right inside your queries -- but at the end of the day, the data is still being transformed client-side.

这篇关于GraphQL 查询访问数组中的第一项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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