Skip to content

Instantly share code, notes, and snippets.

@sultaniman
Last active April 28, 2019 12:52
Show Gist options
  • Save sultaniman/f3e0b68eaa634a1739df809ae5b721bb to your computer and use it in GitHub Desktop.
Save sultaniman/f3e0b68eaa634a1739df809ae5b721bb to your computer and use it in GitHub Desktop.
Sample resolver with standard errors
defmodule IdpWeb.Schema.CityResolvers do
use IdpWeb.Schema.Errors
alias Idp.Geo.Cities
alias Idp.EctoHelpers
def create(_parent, city, _ctx) do
EctoHelpers.action_wrapped(fn ->
Cities.create_city(city)
end)
end
...
def update(_parent, %{city_id: id, name: name}, _ctx) do
case Cities.get_city(id) do
nil ->
@not_found
city ->
EctoHelpers.action_wrapped(fn ->
Cities.update_city(city, %{name: name})
end)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment