Hi folks,
After implementing and reimplementing various dynamic query building mechanisms for resolving graphql fields at several clients I’ve worked for, I went looking for a package that could help me out, but the only one I found required a pretty pricey buy-in, injecting macros throughout your schema files, and it didn’t have a nice integration for absinthe. Eventually I built quarry
and the absinthe integration absinthe_quarry
which you can use as you feel comfortable without leaking the abstraction around your codebase. It gets everything it needs from the parameters you pass. Here’s an example call to the base Quarry
Module
Quarry.build!(Post, filter: %{author: %{name: "John"}}, load: [:author, comments: :user])
Just based on the top level schema module, it can build an ecto query, joining in and reusing those joins for filtering and loading.
The absinthe integration is as simple as calling the top level quarry
helper function, and including meta
tags on nested associations to load them
field :posts, list_of(:post) do
arg :filter, :post_filter
resolve quarry(Post, Repo)
end
object :post do
field :title, :string
field :author, :author, meta: [quarry: true]
end
Check out the readmes and docs for more detail, and I’ve got a tongue-in-cheek blog post walking though why these packages exist, and how you might use them.
The packages are still brand new, so I haven’t implemented all the overrides and escape-hatches that you’d probably want and need in production, but I have github issues in for some of them. Feel free to add thumbs up to the ones that are important to you, or add new issues.