Automatic Persisted Queries

You can use this feature to double the 8kb limit on the query size to 16kb if you are a customer on our Premium plan and above, plus to cache the query in Contentful to decrease the payload delivered through the network.

  • First, you have to send the query and a sha256Hash value of that query:
$curl --location --request POST 'https://graphql.contentful.com/content/v1/spaces/{SPACE}/environments/{ENVIRONMENT}' \
>--header 'Authorization: Bearer {TOKEN}' \
>--header 'Content-Type: application/json' \
>--data-raw '{
> "query": "{__typename}",
> "extensions": { "persistedQuery": { "sha256Hash": "ecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38", "version": 1 } }
>}'
  • Then, you can only send the hash to execute the cached query:
$curl --location --request POST 'https://graphql.contentful.com/content/v1/spaces/{SPACE}/environments/{ENVIRONMENT}' \
>--header 'Authorization: Bearer {TOKEN}' \
>--header 'Content-Type: application/json' \
>--data-raw '{
> "extensions": { "persistedQuery": { "sha256Hash": "ecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38", "version": 1 } }
>}'

Note: If you sent a wrong hash you will get a PersistedQueryMismatch error. If you sent a hash without caching the query first, you will get a PersistedQueryNotFound error.