Building the Resolver

Let’s build the resolver function. It will grab the :input argument for us, and then call a general-purpose PlateSlate.Menu.create_item/1 function that will handle attempting to persist the record:

1: def​ create_item(_, %{​input:​ params}, _) ​do
2: case​ Menu.create_item(params) ​do
3:  {​:error​, _} ->
4:  {​:error​, ​"​​Could not create menu item"​}
5:  {​:ok​, _} = success ->
6:  success
7: end
8: end

Here’s how we’ve implemented PlateSlate.Menu.create_item/1:

 def​ create_item(attrs \\ %{}) ​do
  %Item{}
  |> Item.changeset(attrs)
  |> Repo.insert()
 end

The actual persistence of the ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.