-
-
Save EQuimper/486396713706057096644dd9fb75b971 to your computer and use it in GitHub Desktop.
Arc Uploader resolver for Absinthe Graphql
This file contains 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 MyApp.Schema.ArcResolver do | |
defmacro __using__([uploader: uploader]) do | |
quote do | |
import unquote(__MODULE__), only: [ | |
get_file: 2 | |
] | |
@__arc_upload unquote(uploader) | |
end | |
end | |
defmacro get_file(field, version) do | |
quote do | |
unquote(__MODULE__).get_file(@__arc_upload, unquote(field), unquote(version)) | |
end | |
end | |
def get_file(uploader, field, version) do | |
fn parent, _, _ -> | |
res = apply(uploader, :url, [{parent.picture, parent}, version]) | |
{:ok, res} | |
end | |
end | |
end |
This file contains 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 MyApp.Context.Service do | |
use Ecto.Schema | |
use Arc.Ecto.Schema | |
alias MyApp.Picture | |
schema "services" do | |
field :picture, Picture.Type | |
end | |
end |
This file contains 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 MyApp.Schema.Types do | |
use Absinthe.Schema.Notation | |
use MyApp.Schema.ArcResolver, uploader: MyApp.Picture | |
object :service do | |
field :thumb, :string, resolve: get_file(:picture, :thumb) | |
field :original, :string, resolve: get_file(:picture, :original) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment