GraphQL Errors
The GraphQL Content API responses via GitHub contains errors that occur during the different phases of a request (authentication, validation, schema generation and execution) dependencies. Among these errors there can also be other internal system errors.
The errors returned by the GraphQL API follow the GraphQL error spec via GitHub. There is an additional contentful object in the extensions error property with information relevant to the failed request to facilitate debugging and fixing problems. The contentful object contains the following properties:
code: unique error identifier.requestId: unique request identifier.details: optional object with details about a specific kind of error.
The following is an example of such a response from the API deployment:
List of known errors
Is partial indicates whether for given error partial data response is possible.
For more information, read our tutorials that cover frontend and backend technologies so you can implement GraphQL queries into your application, including languages JavaScript, Android and iOS (requires Apollo).
GraphQL Errors Explained
COLLIDING_TYPE_NAMES
The COLLIDING_TYPE_NAMES error is returned when one or more content type IDs are converted to the same GraphQL type name. For more information about this error, see the Colliding type names section.
Example
Solution
To prevent this error, make sure the content type IDs in your space environment cannot result in the same GraphQL type name. You can either enter two unique random IDs in the creation phase, or provide two distinct names that wouldn’t be converted to the same ID or GraphQL type name later on. For more information on how schemas and the type names are generated for your GraphQL schema, see the Schema generation section.
To fix this error, recreate one of the content types that have colliding IDs, making sure the new ID won’t collide with the second content type ID. You can also use the scripted approach described in the Scripting migrations with the Contentful CLI guide.
Note: Once the collision issue is fixed in Contentful, you also need to purge the cached content to push the fix into production.
COLLIDING_TYPE_NAMES during query execution
We dynamically create the types for GraphQL values based off of their names. As a result, users can inadvertently create naming collisions.
The following example is a common scenario of how a naming collision can occur:
- Create the following content types:
BlogPost,BlogPostContentandBlogPostMoreContent. - Add a reference field called
contentto yourBlogPostcontent type, and allow it to link toBlogPostContentandBlogPostMoreContent. - Create an entry of type
BlogPostwith its content field linking to an entry of typeBlogPostMoreContent. - Query the
BlogPost entryincluding the linked entry. A generic error message is returned expecting only entries of typeBlogPostContentinstead ofBlogPostMoreContent.
Here is a breakdown of what is actually happening:
When generating a BlogPostContent, we create an API-wide collection called BlogPostContentCollection for querying purposes. However, when generating the content field on a BlogPost, we also need to create a collection to enable querying. Unfortunately, this creates a name collision issue as both collections have the same name, but different types. This conflict can cause various issues in the codebase. In some cases, we are able to prevent schema generation. However, sometimes this occurs at query execution.
To fix this, determine what fields are causing a collision and rename one of the conflicting fields.
COLLIDING_FIELD_NAMES
The COLLIDING_FIELD_NAMES error is returned when several field IDs from the same content type are transformed into the same GraphQL field name.
Example
Solution
To prevent this error, make sure the field IDs you’re using on each content type cannot result in the same GraphQL field name. To fix this error, change the ID of one of the colliding fields in question using the web app or the Content Management API.
Note: Once the collision issue is fixed in Contentful, you also need to purge the cached content to push the fix into production.
RESERVED_FIELD_NAME
The RESERVED_FIELD_NAME error is returned when a field ID is transformed into a reserved GraphQL field name. Reserved field names are sys, linkedFrom and contentfulMetadata.
Example
Solution
To fix this error, change the field ID to a value that does not collide with any of the reserved names using the web app or the Content Management API.
UNKNOWN_ENVIRONMENT
The UNKNOWN_ENVIRONMENT error is returned when the requested environment does not exist or when the provided authentication token does not allow access to the specified environment.
Example
Solution
To fix this error you can:
- request an environment from the list of environments that are already enabled for your content delivery token, or
- adjust the token so that it has access to the environment you want to use in your query.
For more information on how authentication to the Content Delivery API and Content Preview API works and how you can configure them, see the Authentication section of the API reference.
UNKNOWN_SPACE
The UNKNOWN_SPACE error is returned when the space ID included in the URL is incorrect.
Example
Solution
To fix this error you can:
- request an environment from the list of environments that are already enabled for your content delivery token, or
- adjust the token so that it has access to the environment you want to use in your query.
For more information on how authentication to the Content Delivery API and Content Preview API works and how you can configure them, see the Authentication section of the API reference.
MISSING_QUERY
The MISSING_QUERY error is returned when the POST request does not contain a payload or when the GET request does not contain the following query parameter: query.
Example
Solution
To fix this error, include a query in the body of a POST request or a query query parameter in the GET request.
QUERY_TOO_BIG
The QUERY_TOO_BIG error is returned when the query exceeds the maximum allowed size.
Example
Solution
To fix this error, divide the query into smaller parts to get the information you need in multiple smaller queries.
INVALID_QUERY_FORMAT
The INVALID_QUERY_FORMAT error is returned when the query is not of type string.
Example
Solution
To fix this error, make sure the query passed in the request is of type string.
INVALID_VARIABLES_FORMAT
The INVALID_VARIABLES_FORMAT error is returned when the variables included in the request are not a valid JSON object.
Example
Solution
To fix this error, check the integrity of the variables sent and make sure the JSON object is valid.
PersistedQueryNotFound
The PersistedQueryNotFound error is returned when you send a hash for a query that is not cached in our server.
Example
Solution
To fix this error, make sure you cached the query first by sending the hash and the query in a previous request.
PersistedQueryMismatch
The PersistedQueryMismatch error is returned when the sha256Hash does not match the expected query hash.
Example
Solution
To fix this error, make sure you hashed the query using the sha256Hash algorithm.
TOO_COMPLEX_QUERY
Disclaimer: The default complexity limit for collections is 100. The query complexity is calculated as the maximum number of entries and assets a query can potentially return.
The TOO_COMPLEX_QUERY error is returned when the calculated query complexity exceeds the maximum complexity allowed.
Example
Solution
To avoid this issue, simplify the query complexity by setting a lower limit in the GraphQL query. You can also limit the depth of the query. For reference fields, it’s recommended to set a limit on the number of allowed links in the content modeling section. If there is a lower number than the default 1000, it will be used to calculate the overall complexity instead.
Examples of actions to optimize a query
- Make sure all the collections queried have a
limitset on them:
- Lower the limits on nested collections to significantly reduce the resulting cost:
- If you know how many entries can be in a specific collection, set the
limitto that number or lower.
- If you have the
linkedFromfield and you know the exact number of entries you are linking to, set thelimitto that number:
- If the query is too deep, fetch the IDs of a nested collection and use a separate query for that collection:
QUERY_OPERATION_NAME_MISMATCH
The QUERY_OPERATION_NAME_MISMATCH error is returned when a GraphQL request is received without a valid or matching operation name. The server cannot determine which operation to execute based on the provided operation name. The error message includes the received operation name and the available operation names found in the query.
Example
Possible causes
- The operation name provided in the GraphQL request does not match any of the operation names defined in the query.
- The GraphQL query does not contain any operation names.
Solution
- Ensure that the operation name provided in the request is spelled correctly and matches one of the operation names defined in the query.
- If the GraphQL query does not contain any operation names, make sure to include the operation name when sending the request.
UNKNOWN_LOCALE
The UNKNOWN_LOCALE error is returned when the requested locale does not exist.
Example
Solution
To fix this error, request one of the available locale codes returned in the error details. For more information about editing a locale, see the Localization with Contentful tutorial.
UNRESOLVABLE_LINK
The UNRESOLVABLE_LINK error is returned when a link cannot be resolved because the target entity does not exist or it is not published.
NOTES:
- When a link cannot be resolved, a
nullvalue is returned on that field. - When a link in an array cannot be resolved, a
nullvalue on its position is returned. - For each link that cannot be resolved, an error object with the details is sent with the response.
To distinguish between single entity links and array links, pay attention to the type in the GraphQL schema and the actual GraphQL response.
Examples
Solution
To fix this error, adjust your query to only request entities that exist and are published. Additionally, you can handle this specific error gracefully in your application.
Skip unresolvable links
You can skip over unresolvable links by filtering where the sys.id_exists is true.
Note: To use the filter, you must have a validation rule set on the many reference field that makes it only accept one content type.
UNEXPECTED_LINKED_CONTENT_TYPE
The UNEXPECTED_LINKED_CONTENT_TYPE error is returned when the linked entry has an unexpected content type linked to it in the validations. This happens when a validation in a field is changed to disallow a specific content type that was previously allowed, while entries with links to that content type still exist.
Example
Solution
To fix this error, you can remove the links to entries to content types that aren’t allowed anymore, or adjust the allowed content types in the linked entry.
RESOURCES_EXHAUSTED
The RESOURCES_EXHAUSTED error is returned when the GraphQL query has used more resources for its execution than allowed.
Example
Solution
To fix this error, split the query into multiple simple queries.
UNRESOLVABLE_RESOURCE_LINK
The UNRESOLVABLE_RESOURCE_LINK error is returned when a Custom external references or Functions query fails.
Example
Solution
To fix this error, you need to check your third-party data query and your entry that is linked to your app.