Packages
absinthe_relay
1.4.0
1.6.0
1.5.2
1.5.1
1.5.0
1.5.0-rc.0
1.5.0-beta.0
1.5.0-alpha.0
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.4.0-rc.1
1.4.0-rc.0
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.3.0-rc.0
1.3.0-beta.1
1.3.0-beta.0
1.2.0
1.2.0-alpha0
1.2.0-alpha.3
1.2.0-alpha.2
1.2.0-alpha.1
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.1
0.8.0
Relay framework support for Absinthe
Current section
Files
Jump to
Current section
Files
lib/absinthe/relay/schema/notation.ex
defmodule Absinthe.Relay.Schema.Notation do
@moduledoc """
Used to extend a module where Absinthe types are defined with
Relay-specific macros and types.
See `Absinthe.Relay`.
"""
@typedoc "A valid flavor"
@type flavor :: :classic | :modern
@valid_flavors [:classic, :modern]
# TODO: Change to `:modern` in v1.5
@default_flavor :classic
@flavor_namespaces [
modern: Modern,
classic: Classic
]
defmacro __using__(flavor) when flavor in @valid_flavors do
notations(flavor)
end
defmacro __using__([]) do
[
# TODO: Remove warning in v1.5
quote do
warning = """
Defaulting to :classic as the flavor of Relay to target. \
Note this defaulting behavior will change to :modern in absinthe_relay v1.5. \
To prevent seeing this notice in the meantime, explicitly provide :classic \
or :modern as an option when you use Absinthe.Relay.Schema or \
Absinthe.Relay.Schema.Notation. See the Absinthe.Relay @moduledoc \
for more information. \
"""
IO.warn(warning)
end,
notations(@default_flavor)
]
end
@spec notations(flavor) :: Macro.t
defp notations(flavor) do
mutation_notation = Absinthe.Relay.Mutation.Notation |> flavored(flavor)
quote do
import Absinthe.Relay.Node.Notation, only: :macros
import Absinthe.Relay.Node.Helpers
import Absinthe.Relay.Connection.Notation, only: :macros
import unquote(mutation_notation), only: :macros
end
end
@spec flavored(module, flavor) :: module
defp flavored(module, flavor) do
Module.safe_concat(module, Keyword.fetch!(@flavor_namespaces, flavor))
end
end