Skip to content

Instantly share code, notes, and snippets.

@bruce
Created November 4, 2016 06:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruce/14d12108405697cd41034c676b72a34f to your computer and use it in GitHub Desktop.
Save bruce/14d12108405697cd41034c676b72a34f to your computer and use it in GitHub Desktop.
Example resolver mapping / wrapping
defmodule Resolution do
@operations %{
organization: {Resolution.Organization, :find}
# lots of others...
}
def resolver(name) do
case @operations |> Map.get(name) do
{mod, fun} ->
fn
parent, args, info ->
apply(mod, fun, [parent, args, info])
|> handle_errors
end
nil ->
raise ArgumentError, "No resolver found for #{name}"
end
end
# handle_errors is defined here
end
defmodule Schema do
use Absinthe.Schema
import Resolution, only: [resolver: 1]
query do
# Example field definition
field :organization, :organization do
arg :id, non_null(:id)
resolve resolver(:organization)
end
end
# rest of schema...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment