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â |
â ... |
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.