enewbury

enewbury

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.
https://github.com/enewbury/quarry
https://github.com/enewbury/absinthe_quarry

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.

Showing Posts 1 to 2

mayel

mayel

Hi @enewbury :slight_smile: as a user of Absinthe and also having gone on similar journey of looking for query building libraries this is very interesting!
Thought I’d point you to a couple libraries/functions I currently use if they can help for possible inspiration or integration:

  • ecto_shorts by @MikaAK is a rare library that doesn’t rely on macros to accomplish dynamic query building
  • join_preload which helps to easily join & preload associations (using Query.preload rather than Repo.preload), though I’d love a non-macro way of doing the same…
  • reusable_join in the same library which de-duplicates joins, though your if Ecto.Query.has_named_binding?(query, binding) may be achieving the same goal?
MikaAK

MikaAK

Hey thanks mayel for the tag!

There’s also a blog post to accompany ecto shorts as well as a podcast!
Learn Elixir | Creating Reusable Ecto Code (working through a deploy issue breaking styles currently, hurray for swapping to a M1 mac)
https://elixirmix.com/reusable-ecto-code-with-mika-kalathil-emx-164

— All posts loaded —

Where Next? Top

Trending in Announcing Top

type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews