notation.ex (1637B)
1 defmodule Absinthe.Schema.Prototype.Notation do 2 @moduledoc false 3 4 defmacro __using__(opts \\ []) do 5 content(opts) 6 end 7 8 def content(_opts \\ []) do 9 quote do 10 use Absinthe.Schema 11 @schema_provider Absinthe.Schema.Compiled 12 @pipeline_modifier __MODULE__ 13 14 directive :deprecated do 15 arg :reason, :string 16 17 on [ 18 :field_definition, 19 :input_field_definition, 20 # Technically, argument deprecation is not yet defined by the GraphQL 21 # specification. Absinthe does provide some support, but deprecating 22 # arguments is not recommended. 23 # 24 # For more information, see: 25 # - https://github.com/graphql/graphql-spec/pull/525 26 # - https://github.com/absinthe-graphql/absinthe/issues/207 27 :argument_definition, 28 :enum_value 29 ] 30 31 expand &__MODULE__.expand_deprecate/2 32 end 33 34 def pipeline(pipeline) do 35 pipeline 36 |> Absinthe.Pipeline.without(Absinthe.Phase.Schema.Validation.QueryTypeMustBeObject) 37 |> Absinthe.Pipeline.without(Absinthe.Phase.Schema.DeprecatedDirectiveFields) 38 end 39 40 @doc """ 41 Add a deprecation (with an optional reason) to a node. 42 """ 43 @spec expand_deprecate( 44 arguments :: %{optional(:reason) => String.t()}, 45 node :: Absinthe.Blueprint.node_t() 46 ) :: Absinthe.Blueprint.node_t() 47 def expand_deprecate(arguments, node) do 48 %{node | deprecation: %Absinthe.Type.Deprecation{reason: arguments[:reason]}} 49 end 50 51 defoverridable(pipeline: 1) 52 end 53 end 54 end