Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apollo GraphQL keeps receiving requests with no queries or mutations being made

I was learning GraphQL and about to finish the tutorial and this never happened before.

The problem is that the GraphQL server keeps receiving requests after opening GraphQL Playground in the browser even though no query or mutation is made.

I see these sort of responses being returned by the server:

{
    "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\""
      }
    ]
}
like image 871
Rario Avatar asked Sep 21 '19 09:09

Rario


People also ask

How do I clear the Apollo client cache?

Resetting the cache This method is asynchronous, because it also refetches any of your active queries. To reset the cache without refetching active queries, use client. clearStore() instead of client. resetStore() .

How do you handle errors in Apollo GraphQL?

By default, Apollo Client throws away partial data and populates the error. graphQLErrors array of your useQuery call (or whichever hook you're using). You can instead use these partial results by defining an error policy for your operation. If the response includes GraphQL errors, they are returned on error.

What is difference between query and Mutation in GraphQL?

While we use queries to fetch data, we use mutations to modify server-side data. If queries are the GraphQL equivalent to GET calls in REST, then mutations represent the state-changing methods in REST (like DELETE , PUT , PATCH , etc).


1 Answers

This is expected behavior.

GraphQL Playground issues an introspection query to your server. It uses the result of that query to provide validation and autocompletion for your queries. Playground will send that query to your server repeatedly (every 2 seconds by default) so that if your schema changes, these changes can be immediately reflected in the UI (although there's an issue with this feature at the moment).

You can adjust the relevant settings (click on the settings icon in the top right corner of the Playground UI) to either change the polling frequency or turn it off entirely:

  '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

However, the behavior you're seeing is only related to Playground so it's harmless and won't impact any other clients connecting to your server.

like image 165
Daniel Rearden Avatar answered Oct 20 '22 17:10

Daniel Rearden