There are several error types in the GraphQL API and you may come across different ones depending on the operations you are trying to perform.
The Saleor GraphQL API handles the following three types of errors.
This error occurs if, while performing some specified operation, you provide wrong or unrecognized input data. The GraphQL checks the syntax as you write and, if you are trying to perform an unknown operation, you will be notified by the editor you are using. If you proceed with sending the request, you will get a syntax error.
Below is an example of an error triggered by the wrong syntax. The following query tries to fetch the
fullName field which doesn't exist on the
Sending this query to the server would result in the following syntax error:
This type of error occurs when the user passes invalid data as the mutation input. For example, while creating a new user, you provide an email address that is already being used in another user's account. It is therefore not unique and, as a result, you will get a validation error.
Validation errors are part of the schema, which means that we need to include them in the query to get them explicitly. For example, in all mutations, they can be obtained through the errors field.
Below is an example of an error triggered by validation issues:
Validation errors are returned in a dedicated error field inside mutation results:
Although all error types contain a
message field, the returned message is only meant for debugging and is not suitable for display to your customers. Please use the
code field and provide your own meaningful error messages.
This type of error occurs when you are trying to perform a specific operation but you are not authorized to do so; in other words, you have no sufficient permissions assigned.
Below is an example of an error triggered by insufficient authorization. The
staffUsers query requires appropriate admin permissions:
Executing it without proper permission would result in the following error: