为 Github GraphQL 搜索选择 * [英] Select * for Github GraphQL Search

查看:19
本文介绍了为 Github GraphQL 搜索选择 *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Github Search v4 (GraphQL) 相对于 v3 的优势之一是它可以有选择地选择我们想要的字段,而不是总是全部获取.但是,我现在面临的问题是如何获取某些字段.

One of the advantage of Github Search v4 (GraphQL) over v3 is that it can selectively pick the fields that we want, instead of always getting them all. However, the problem I'm facing now is how to get certain fields.

我尝试了在线帮助,但它对我来说更多的是卷积而不是帮助.直到现在,我仍然无法找到返回存储库的大小、分数和未解决问题的字段.

I tried the online help but it is more convolution to me than helpful. Till now, I'm still unable to find the fields for size, score and open issues for the returned repository(ies).

这就是为什么我想知道是否有办法将它们全部获取,例如 SQL 中的 Select *.谢谢.

That's why I'm wondering if there is a way to get them all, like Select * in SQL. Thx.

推荐答案

GraphQL 要求在请求一个字段时,您还请求该字段的选择集(一个或多个属于该字段类型的字段),除非该字段解析到一个标量,如字符串或数字.这意味着不幸的是没有获取所有可用字段"的语法——您总是必须指定您希望服务器返回的字段.

GraphQL requires that when requesting a field that you also request a selection set for that field (one or more fields belonging to that field's type), unless the field resolves to a scalar like a string or number. That means unfortunately there is no syntax for "get all available fields" -- you always have to specify the fields you want the server to return.

除了仔细阅读文档之外,还有两种其他方法可以让您更好地了解可用字段.一个是 GraphQL API Explorer,可让您实时尝试查询.它只是一个 GraphiQL 界面,这意味着当您编写查询时,您可以通过按 Shift+SpaceAlt 来触发自动完成功能+Space 查看可用字段列表.

Outside of perusing the docs, there's two additional ways you can get a better picture of the fields that are available. One is the GraphQL API Explorer, which lets you try out queries in real time. It's just a GraphiQL interface, which means when you're composing the query, you can trigger the autocomplete feature by pressing Shift+Space or Alt+Space to see a list of available fields.

如果你想查找特定类型的字段,你也可以直接询问 GraphQL :)

If you want to look up the fields for a specific type, you can also just ask GraphQL :)

query{
  __type(name:"Repository") {
    fields {
      name
      description
      type {
        kind
        name
        description
      }
      args {
        name
        description
        type {
          kind
          name
          description
        }
        defaultValue
      }
    }
  }
}

这篇关于为 Github GraphQL 搜索选择 *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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