March 2018
Intermediate to advanced
304 pages
6h 59m
English
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 ...
Read now
Unlock full access