Created
November 4, 2016 06:38
-
-
Save bruce/14d12108405697cd41034c676b72a34f to your computer and use it in GitHub Desktop.
Example resolver mapping / wrapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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