Skip to main content

此版本的 GitHub Enterprise 已停止服务 2022-10-12. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

使用 Explorer

GraphQL Explorer 是浏览器中的集成开发环境,包含文档、语法重点和验证错误,可用于查询实际的 GitHub 数据。

关于 GraphQL Explorer

GraphiQL,在本文档中也称为 GraphQL 浏览器,是“浏览器内的图形交互式 GraphQL IDE”。

使用 GraphiQL

若要使用 GraphiQL 应用,可从 https://github.com/skevy/graphiql-app 下载并安装。

配置 GraphiQL

  1. 获取 OAuth � �记
  2. 启动 GraphiQL。
  3. 在 GraphiQL 的右上角,单击“编辑 HTTP � �头”。
  4. 在“键”字段中,选择 。 在“值”字段中,输入 Bearer <token>,其中 <token> 是� 生成的 OAuth 令牌。 graphiql � �头
  5. 单击该令牌右侧的复选� �记进行保存。
  6. 要返回编辑器,请在“编辑 HTTP � �头”模式外部单击。
  7. 在“GraphQL 终结点”字段中,输入 http(s)://<em>HOSTNAME</em>/api/graphql
  8. 在“方法”下拉菜单中选择“POST” 。

注意:有关为何选择 POST 作为方法的详细信息,请参阅“与 GraphQL 通信”。

您可以通过自我查询来测试您的访问:

query {
  viewer {
    login
  }
}

如果一切运行正常,将会显示您的登录信息。 您已设置完成,可以开始查询。

访问边� �文档

GraphQL 架构中的所有类型都包含一个编译到文档中的 description 字段。 该浏览器页面右侧可折� 的“文档”窗� �可用于浏览有关类型系统的文档。 文档将自动更新,并� 除已弃用的字段。

“文档”边� �包含的内容与引用下的架构自动生成的内容相同,但有些地方的� �式不同。

使用变量窗� �

一些示例调用包括如下编写的变量

query($number_of_repos:Int!){
  viewer {
    name
     repositories(last: $number_of_repos) {
       nodes {
         name
       }
     }
   }
}
variables {
   "number_of_repos": 3
}

这是通过 cURL POST 提交调用的正确� �式(但要避免使用换行符)。

如果要在浏览器中运行调用,请在主窗� �中输入 query 字段,并在其下方的“查询变量”窗� �中输入变量。 在浏览器中省略 variables 一词:

{
   "number_of_repos": 3
}

请求支持

For questions, bug reports, and discussions about GitHub Apps, OAuth Apps, and API development, explore the APIs and Integrations discussions on GitHub Community. The discussions are moderated and maintained by GitHub staff, but questions posted to the forum are not guaranteed to receive a reply from GitHub staff.

Consider reaching out to GitHub Support directly using the contact form for:

  • guaranteed response from GitHub Enterprise Server staff
  • support requests involving sensitive data or private concerns
  • feature requests
  • feedback about GitHub Enterprise Server products

排查错误

由于 GraphQL 可以自省,� 此浏览器支持:

  • 基于当前架构的智能输入提示
  • 键入时预提示验证错误

如果输入的查询� �式不正确或未通过架构验证,则会弹出错误警示窗口。 如果您运行查询,错误将返回响应窗� �中。

GraphQL 响应中包含多个键:data 哈希和 errors 数组。

{
  "data": null,
  "errors": [
    {
      "message": "Objects must have selections (field 'nodes' returns Repository but has no selections)",
      "locations": [
        {
          "line": 5,
          "column": 8
        }
      ]
    }
  ]
}

您可能会遇到与架构� 关的意外错误。 如果发生这种情况,该消息将包含一个参考代� �,供您在报告问题时使用:

{
  "data": null,
  "errors": [
    {
      "message": "Something went wrong while executing your query. This is most likely a GitHub bug. Please include \"7571:3FF6:552G94B:69F45B7:5913BBEQ\" when reporting this issue."
    }
  ]
}

注意:GitHub 建议,在将数据用于生产环境之前,先检查其是否有错误。 在 GraphQL 中,失败并不意味着全部错误:在一些 GraphQL 查询失败的同时,另一些查询可能成功。