Skip to content

Instantly share code, notes, and snippets.

@bruce
Created February 8, 2017 17:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruce/e5307411f757c6ac585005d7f8f37e68 to your computer and use it in GitHub Desktop.
Save bruce/e5307411f757c6ac585005d7f8f37e68 to your computer and use it in GitHub Desktop.
Extending an Absinthe schema using custom, app-specific macros
defmodule MyApp.Color do
@moduledoc """
Just an example source of the values
"""
def list do
~w(red green blue)a
end
end
defmodule MyApp.Schema.Macros do
@moduledoc """
App-specific macros to extend the schema
"""
defmacro color_definitions do
for color <- MyApp.Color.list() do
quote do: value unquote(color)
end
end
end
defmodule MyApp.Schema do
use Absinthe.Schema
# Get the macros
import MyApp.Schema.Macros
enum :colors do
# Use the macro
color_definitions()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment