cjbottaro
I want to programmatically generate input objects from introspecting my schema, but I can’t figure out the metaprogramming to do so.
Essentially, I want this desired module def:
defmodule InputObjects do
use Absinthe.Schema.Notation
input_object :user_filter do
field :id, :integer_filter
field :email, :string_filter
end
end
But from coming from variables:
defmodule InputObjects do
use Absinthe.Schema.Notation
name = :user_filter
fields = [
{:id, :integer_filter},
{:email, :string_filter}
]
input_object name do
Enum.each fields, fn {name, type} ->
field name, type
end
end
end
How to do this? Thanks for the help!
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
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
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #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
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Marked As Solved- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Eiji
@cjbottaro The problem with
absintheis that they are using macros and work only with raw data (not in variables).This is because
absintheis making some checks on raw data.Let’s say we have such simple code:
As you can see it’s not possible to work on it without proper quoting. Same goes if you want to use
absinthemacros i.e. you need to pass raw data.However this does not mean that it’s not possible to pass variables - this only means that we need pass raw data to absinthe macros. It should be hint for more experienced developers. Just write your own macro!
Firstly you need to know what
ASTyou need to return:Let’s split it:
{:field, [], [:id, :integer_filter]}As you can see it’s
field/2macro AST{:__block__, [], […]}Block here is list of
ASTexpressions inside function which are not single literals. For example:def sample(…) do 5 endgives us just raw5in place of whole:__block__part, but if we add one more line with same literal they would be arguments in:__block__AST.Finally
{:input_object, [], [:user_filter, [do: …]]}Similarly to 1st point it’s ast for
input_object/2call. Heredo … endgoes to 2nd argument which is keyword list[do: …]. As in 2nd point we could have:[do: 5]or[do: {:__block__, [], […]}]. For us it’s 2nd case as we will never contain literals there.From this here goes example code:
and here is usage:
Sorry if I made any typo - I wrote everything from memory.
Last Post!
Eiji
Firstly
ASTis not extremely low level if we are talking aboutElixir.Well … I have one really good example from my experience …
My first job … I have worked with Ruby/Rails. I saw really small monkey patching usage from someone who was more experienced than me. I liked how it’s simple (so there was no need to change existing code) and I have stupidly changed file with just few lines of monkey patching into weird file with hundreds of lines with monkey patching.
If something is supported it does not mean that it should be always used. Especially when we are talking about evals. Look … I believe that
Joomla!andWordpressdevelopers are not stupid. Same goes to developers of (at least most popular) extensions for those projects. The problem is that lots of sites was trivially hacked by addingPHPcode into image files - just because they used eval.Sure, one module looks safe, but can you guarantee that this will be still safe after few rotations in
devteam? Can you guarantee that it will be still safe after somebody in team decides to move such generator (withevalcall) to open source library? Software is changing really rapidly.If we are going always with easiest solution then we will end with something like
Windowsin few weeks/months.Windowswas created by definitely good developers, but looking how it changes in years we see that something is definitely wrong. For example compare modern (with rewritten code)Plasma 5features and requirements with what offersWindows’s builtin window manager. I can’t do even as good job as that made in both projects, but still I (being not experienced in OS programming) see huge differences.Also my solution is not about only “low level”. We have here typical pattern matching which prevents to add data of any type. We can always add simple guard to check if module have
Schemapart in list too without bigger problem.Summary:
Therefore I’m not sure what’s wrong with my hint.