【问题标题】:Apollo GraphQL keeps receiving requests with no queries or mutations being madeApollo GraphQL 不断接收请求,没有进行查询或突变
【发布时间】:2020-01-22 03:17:07
【问题描述】:

我正在学习 GraphQL,即将完成教程,这在以前从未发生过。

问题是 GraphQL 服务器在浏览器中打开 GraphQL Playground 后一直在接收请求,即使没有进行查询或更改。

我看到服务器返回了这些类型的响应:

{
    "name":"deprecated",
    "description":"Marks an element of a GraphQL schema as no longer supported.",
    "locations":[
      "FIELD_DEFINITION",
      "ENUM_VALUE"
    ],
    "args":[
      {
          "name":"reason",
          "description":"Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax (as specified by [CommonMark](https://commonmark.org/).",
          "type":{
            "kind":"SCALAR",
            "name":"String",
            "ofType":null
          },
          "defaultValue":"\"No longer supported\""
      }
    ]
}

【问题讨论】:

    标签: javascript node.js typescript graphql apollo


    【解决方案1】:

    这是预期行为。

    GraphQL Playground 向您的服务器发出introspection query。它使用该查询的结果为您的查询提供验证和自动完成功能。 Playground 会将该查询重复发送到您的服务器(默认每 2 秒),因此如果您的架构发生更改,这些更改可以立即反映在 UI 中(尽管目前有 an issue 具有此功能)。

    您可以调整相关设置(单击 Playground UI 右上角的设置图标)以更改轮询频率或完全关闭它:

      'schema.polling.enable': true, // enables automatic schema polling
      'schema.polling.endpointFilter': '*localhost*', // endpoint filter for schema polling
      'schema.polling.interval': 2000, // schema polling interval in ms
    

    但是,您看到的行为仅与 Playground 有关,因此它是无害的,不会影响连接到您服务器的任何其他客户端。

    【讨论】:

    • 谢谢!在我禁用schema.polling 后,它就不再发生了。
    猜你喜欢
    • 2020-11-04
    • 2019-12-06
    • 2021-04-23
    • 2021-07-05
    • 2018-03-02
    • 2019-11-20
    • 2019-06-13
    • 2019-07-23
    相关资源
    最近更新 更多