Skip to content

Instantly share code, notes, and snippets.

@vic
Created Dec 15, 2016
Embed
What would you like to do?
Macro schema objects for absinthe. see https://github.com/absinthe-graphql/absinthe/issues/232
defmodule Absinthe.Schema.Notation.Macro do
defmacro macro_field(name, a, b) do
macro(:field, [name, a, b])
end
defmacro macro_object(name, a) do
macro(:object, [name, a])
end
defmacro macro_input_object(name, a) do
macro(:input_object, [name, a])
end
defp macro(type, args = [name | _]) do
quoted = quote do
Absinthe.Schema.Notation.unquote({type, [], nil})(unquote_splicing(args))
end
quote do
defmacro unquote({name, [], nil}) do
unquote(quoted |> Macro.escape)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment