Handling Mutation Errors

In a perfect world, users would provide the correct data, conditions would always be met, mutations would execute cleanly, and changes would be persisted flawlessly. This isn’t a perfect world, however, so we need to deal with errors that might occur when executing our mutations. We’ll cover two major strategies that you can use to report errors to users. While you can’t always make them happy, you can at least let them know what went wrong.

Before we dig into error handling, we need to set up a good example. Let’s add a constraint in our PlateSlate application business logic so that we can easily trigger an error when creating menu items.

Right now in our PlateSlate application, we’re very permissive about menu item ...

Get Craft GraphQL APIs in Elixir with Absinthe now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.