arjan
Would there be interest in a (small) DSL for writing graphql queries in Elixir?
In my tests I am now annoyed by the fact that GraphQL does not indent very well (writing gigantic GraphQL queries inside ~s(...)), so I’m tempted to write a macro which takes something like this:
graphql = query [id: :string] do
orders(a: id) do
id
title
order_lines do
id
price
end
end
end
And automagically converts it into this string:
query ($id: String) { orders(id: $id) { id title order_lines { id price } } }
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
I’m posting this in response to Jose’s recent tweet (Cr. link) :
People are sleeping on Elixir for a coding harness:
Hot-code swappi...
New
Hello,
I wrote Stop My Hand, a Scattergories-like web application using Phoenix/LiveView as my learning project for Elixir (after readin...
New
AcmeScript — Writing JS hooks as if I were still using Elixir
I’ve been having fun building a little something over the last few days: Ac...
New
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
This is a good question. TBH I’m not sure it gets you much over using triple quotes:
GraphQL syntax is so very nearly a DSL on its own already. Certainly for tests I’m not sure that a DSL adds much value.
arjan
You’re right.. the
"""strings solve most issues. Except that it’s not smart with auto-indentation in the string. But I guess that’s an Emacs issuekeathley
We just use triple quoted strings for queries and its working out pretty well. I’m not sure what the main benefits a DSL would offer over just using strings. There could be some benefit to an elixir, graphql client that provided introspection, type hints, and some sort of query validation though.
OvermindDL1
Heck yes! I’ve been wanting one for a while! I’ve just been writing strings so far, not got around to trying to make a DSEL yet. ^.^
Doing it in Elixir might be a bit more verbose, but if the DSEL is designed well then it could catch a lot of bugs at compile-time, especially if it introspects an Absinthe schema to verify against. ^.^
benwilson512
I hear you, but I actually think a sigil would be the best thing for that IE
Having actual graphql docs in tests has provided me with tons of utility because I can just directly link to test cases when other developers ask for examples. Obviously GraphiQL is a good exploration tool too, but it’s been pretty handy to have a full set of tested docs ready for usage.
arjan
Yes, it would indeed validate the given schema.
I’ve made some progress on this, I’ll extract it from my current code base and put it in a repo.
OvermindDL1
Actually, I wonder about combining the ideas.
What about a text definition (via “”") but it calls absinthe at compile-time to validate it is a valid ~
schema~/call (does absinthe have a way to validate a call without actually calling it?).benwilson512
Absinthe works a lot like a compiler, so you just build a pipeline of phases up prior to the actual resolution point:
It isn’t quite as easy as I’d like. I’m gonna add a phase I think that will automatically run the result phase ONLY on error. Either way, this should get you going for now.
arjan
I’ve put it up: GitHub - arjan/absinthe_dsl: Elixir DSL for constructing GraphQL queries · GitHub
Works like this:
Contributors welcome
OvermindDL1
Meant a valid query, not schema. ^.^;