Automatic Persisted Queries (APQ)

Stellate supports automatic persisted queries (or APQs for short), which can help drastically reduce the size of your GraphQL payloads sent from clients to Stellate edge locations.

🚧

Apollo Client Minimum Version

If you are using Apollo Client, please make sure that you are using version 3.6.2 or newer.

Version 3.6.2 fixed a bug with Apollo Client were a PersistedQueryNotFound error with a HTTP/4xx status code, like Stellate is using, would not result in a retry, but instead a client side error.

Here is an example request using the { __typename } query. The initial request would look like the following curl command.

curl -g -X POST https://spacex-api.stellate.sh \
  -H "Content-Type: application/json" \
  -d '{
    "query": "{__typename}",
    "extensions": {
      "persistedQuery": {
        "version": 1,
        "sha256Hash": "ecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38"
      }
    }
  }'

Subsequent requests for the same query would only need to use the hash of the operation, dropping the query key completely.

curl -g -X POST https://spacex-api.stellate.sh \
  -H "Content-Type: application/json" \
  -d '{
    "extensions": {
      "persistedQuery": {
        "version": 1,
        "sha256Hash": "ecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38"
      }
    }
  }'

This example uses a very small query, which doesn't show the full impact APQs can have. However, keep in mind that the query can be of arbitrary length, whereas the sha256 hash will always have a constant length.

You can read more about Automatic Persisted Queries on the Apollo Documentation at https://www.apollographql.com/docs/apollo-server/performance/apq/ (among other pages).


Did this page help you?