Hello everyone, I’m looking to generate objects, queries , and mutations dynamically. The problem is that we can have many macros inside of other macros
For example, I want to generate the following object:
object :comment do
field(:id, :id)
field(:body, :string)
field(:author_id, :id)
field(:author, :author, resolve: assoc(:author)) do
complexity(fn _, child_complexity ->
child_complexity + 1000
end)
arg(:filter, :filters_avatar)
resolve(&AuthorResolver.all/3)
end
end
I’ve tried to use basic notations as:
def object_wrapper(identifier, fields) do
object =
quote do
object unquote(identifier) do
for {name, data_type} <- fields do
field(unquote(name), unquote(data_type))
end
end
end
Code.eval_quoted(object, [identifier: identifier, fields: fields], __ENV__)
end
Do you have any recommendations on which approach should I take?