arjan
DSL for writing GraphQL in Elixir?
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 } } }
First Post!
benwilson512
This is a good question. TBH I’m not sure it gets you much over using triple quotes:
query = """
query ($id: String) {
orders(id: $id) { id title orderLines { id price } }
}
"""
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.
Most Liked
arjan
I’ve put it up: GitHub - arjan/absinthe_dsl: Elixir DSL for constructing GraphQL queries · GitHub
Works like this:
query = query(arg: :string) do
users(id: arg) do
name
end
end
assert query == "query ($arg: String) { users(id: $arg) { name } }"
Contributors welcome ![]()
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 issue ![]()
benwilson512
Last Post!
Trending in Discussions
Other Trending Topics
Chat & Discussions>Discussions
Latest on Elixir Forum
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









