Prompt
Why are my GraphQL queries failing in Contentful
Latest observation
Contentful GraphQL queries usually fail for a few common reasons. The fastest way to narrow it down is to look at the exact error message, but here are the usual culprits:
1) Using the wrong endpoint
Contentful GraphQL uses different endpoints depending on the environment:
- Preview:
https://graphql.contentful.com/content/v1/spaces/{space_id}/environments/{env_id} - Delivery: same path, but with the Delivery API token
If you’re hitting a CDA/CPA REST endpoint with GraphQL syntax, it will fail.
2) Missing or incorrect authorization
You need the correct token in the Authorization header:
Authorization: Bearer YOUR_CONTENTFUL_TOKEN
Also make sure you’re using the right token type:
- Delivery API token for published content
- Preview API token for drafts/unpublished content
3) Querying fields that don’t exist
GraphQL only allows fields that exist in your Contentful content model.
Common issues:
- Typo in field name
- Wrong casing
- Field not present in that content type
- Field renamed in Contentful but not updated in your query
Example:
{
blogPostCollection {
items {
title
body
}
}
}
If body doesn’t exist, the query fails.
4) Wrong type names / collection names
Contentful GraphQL type names are based on your content type IDs, not always the display name.
For example:
- Content type ID:
blogPost - GraphQL query:
blogPostCollection
If your ID is different, the generated GraphQL field will be different too.
5) Missing linked field sub-selection
If a field is an asset or linked entry, you often need to select nested fields.
Bad:
{
blogPostCollection {
items {
image
}
}
}
Better:
{
blogPostCollection {
items {
image {
url
}
}
}
}
6) Locale issues
If your space uses locales, some queries need explicit locale handling, and some fields may be missing in the default locale.
Example:
{
blogPostCollection(locale: "en-US") {
items {
title
}
}
}
7) Field type mismatch
If you query a field as one shape but it’s actually another, GraphQL will reject it.
Example:
- You expect
authorto be an entry - But it’s actually plain text
Then this would fail:
author {
name
}
8) Not using the right environment
If your content is in a non-default environment, the query must point to that environment in the URL.
9) Permissions / CORS / network issues
Sometimes it’s not the query itself:
- token lacks access
- environment not published
- request blocked by CORS in browser
- rate limiting
- malformed JSON body
10) Query complexity or invalid variables
If you’re using variables, make sure:
- variable names match exactly
- the GraphQL operation declares them properly
- input types are correct
Example:
query GetPost($slug: String!) {
blogPostCollection(where: { slug: $slug }) {
items {
title
}
}
}
What to check first
- The exact error message returned by Contentful
- Your endpoint URL
- Your auth token
- The content type ID and field names
- Whether the field is a linked entry/asset or a scalar
- Whether you’re using the correct locale/environment
If you want, paste:
- your GraphQL query
- the error message
- your content type IDs/field names
and I can help pinpoint the exact issue.
Brands