View Source AbsintheQuarry.Helpers (AbsintheQuarry v0.0.1)
Functions to integrate quarry with your absinthe schema
Link to this section Summary
Functions
Returns a resolver function that runs a quarry query.
Link to this section Types
@type quarry_key_fun() :: (Absinthe.Resolution.source(), Absinthe.Resolution.arguments(), Absinthe.Resolution.t() -> quarry_tuple())
@type quarry_tuple() :: {:middleware, AbsintheQuarry.Middleware.Quarry, term()}
Link to this section Functions
@spec quarry(atom(), Ecto.Repo.t()) :: quarry_key_fun()
Returns a resolver function that runs a quarry query.
field :posts, list_of(:post), resolve: quarry(Post, Repo)This resolver will use arguments filter, sort, limit, and offset and apply them to the quarry options.
field :posts, list_of(:post), resolve: quarry(Post, Repo) do
arg :filter, :post_filter
arg :sort, :post_sort
arg :limit, :integer
arg :offset, :ineger
endThe resolver will check any selected fields and prelaod them if the appropriate meta tag is specified
object :post do
field :author, :author, meta: [qurry: true]
end
...
field :posts, list_of(:post), resolve: quarry(Post, Repo)
Note, has_many sub fields will also be checked for the quarry args, see README for details
object :post do
field :comments, :comment, meta: [qurry: true] do
arg :filter, :comment_filter
end
end
...
field :posts, list_of(:post), resolve: quarry(Post, Repo)The double underscore __ will indicate to quarry the value to the left is the field name
and the value to the right is the quarry operator.
input_object :user do
field :name__starts_with, :string
endThe double underscore in sort enums will also indicate a separation of fields so that you can sort on sub fields
enum :post_sort do
value :title
value :user__name
end