Errors Management
While doing Mutations, you might encounter some errors.
Prevent Errors:
There are a couple of ways to prevent errors from happening.
Check permissions:
Most of the object types — that are subject to permission checks — are linked to an ...Action
object. This object will describe the different actions you can have on the given object.
For example, on the Story
object you'll have the StoryActions
object.
If you want to delete a Story
, you need to check if the delete
field is true before using the storyDelete
mutation.
Check for deprecations:
We might from time to time deprecate some fields. You should check every once in a while if some fields you are using are deprecated and/or will be removed in the future. As you might know, querying an inexistent field will crash the whole query.
Error Management
After checking all the above you still might encounter errors.
Every mutation comes with an errors
field.
This field is an Array of errors that were found during the execution of your mutation. All errors in the array implement the MutationError
interface.
It is recommended to query this field.
graphqlmutation storyBroadcast($input: StoryBroadcastInput!) {storyBroadcast(input: $input) {story {id}errors {__typename... on MutationError {path}... on ObjectNotFoundError {path}}}}
Each mutation has a unique set of possible errors. Querying __typename
shows which error occurred, and path
describes the problematic field, for instance input.id
.
Providing a faulty story ID in the mutation above, you'll receive the following response
response{"data": {"storyBroadcast": {"errors": [{"__typename": "ObjectNotFoundError","path": "input.id"}],"story": null}}}
Here you notice the ObjectNotFoundError
and "path": "input.id"
describing that the provided id
was not found.