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

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
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
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews