Tuples
Learn how to use tuples in GraphQL.
We'll cover the following...
Using tuples
Field resolver functions return tuple values to indicate their result:
Press + to interact
def create_item(_, %{input: params}, _) docase Menu.create_item(params) do{:error, _} ->{:error, "Could not create menu item"}{:ok, _} = success ->successendend
The return value for PlateSlate.Menu.create_item/1
is a tuple and we do a bit of post-processing on the value to return a nicely formatted value for Absinthe to include in the response. Successful values are returned untouched, but error values are replaced with a generic message, “Could not ...