Our First Module

In Chapter 5, ​Making a Change with Mutations​, we added several resolution functions that all copied an error-handling function we first developed to power the :create_menu_item mutation field. This error-handling function enabled the system to give users feedback about errors that bubble up from the underlying database—from internal schema-validation problems like missing and badly formatted arguments to database constraint violations.

Let’s take a look at that resolver again:

​ ​def​ create_item(_, %{​input:​ params}, _) ​do​
​  ​case​ Menu.create_item(params) ​do​
​  {​:error​, changeset} ->
​  {​:ok​, %{​errors: ...

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.