diff --git a/lib/absinthe/phase/schema/compile.ex b/lib/absinthe/phase/schema/compile.ex index 5046119371..7e36f6f073 100644 --- a/lib/absinthe/phase/schema/compile.ex +++ b/lib/absinthe/phase/schema/compile.ex @@ -8,7 +8,10 @@ defmodule Absinthe.Phase.Schema.Compile do %{schema_definitions: [schema]} = blueprint - type_ast = build_types(schema.type_artifacts) + prototype_schema = Keyword.fetch!(opts, :prototype_schema) + + type_ast = build_types(schema.type_artifacts, prototype_schema) + directive_ast = build_directives(schema.directive_artifacts) type_list = @@ -27,8 +30,6 @@ defmodule Absinthe.Phase.Schema.Compile do {type_def.identifier, type_def.name} end) - prototype_schema = Keyword.fetch!(opts, :prototype_schema) - metadata = build_metadata(schema) implementors = build_implementors(schema) @@ -86,7 +87,7 @@ defmodule Absinthe.Phase.Schema.Compile do end end - def build_types(types) do + def build_types(types, prototype_schema) do for type <- types do if !type.definition, do: @@ -108,9 +109,13 @@ defmodule Absinthe.Phase.Schema.Compile do end end |> Enum.concat([ - quote do - def __absinthe_type__(_type) do - nil + if prototype_schema == Absinthe.Schema.Prototype do + quote do + def __absinthe_type__(_type), do: nil + end + else + quote do + def __absinthe_type__(type), do: unquote(prototype_schema).__absinthe_type__(type) end end ]) diff --git a/test/absinthe/introspection_test.exs b/test/absinthe/introspection_test.exs index c2e5dd1eba..1a72603d38 100644 --- a/test/absinthe/introspection_test.exs +++ b/test/absinthe/introspection_test.exs @@ -89,6 +89,88 @@ defmodule Absinthe.IntrospectionTest do end end + describe "introspection of complex directives" do + defmodule ComplexDirectiveSchema do + use Absinthe.Schema + use Absinthe.Fixture + + defmodule ComplexDirectivePrototype do + use Absinthe.Schema.Prototype + + input_object :complex do + field :str, :string + end + + directive :complex_directive do + arg :complex, :complex + + on [:field] + end + end + + @prototype_schema ComplexDirectivePrototype + + query do + field :foo, + type: :string, + args: [], + resolve: fn _, _ -> {:ok, "foo"} end + end + end + + test "renders type for complex directives" do + result = + """ + query IntrospectionQuery { + __schema { + directives { + name + args { + name + description + type { + kind + name + } + defaultValue + } + } + } + } + """ + |> run(ComplexDirectiveSchema) + + assert {:ok, + %{ + data: %{ + "__schema" => %{ + "directives" => directives + } + } + }} = result + + assert Enum.any?(directives, fn directive -> + match?( + directive, + %{ + "name" => "complexDirective", + "args" => [ + %{ + "type" => %{ + "kind" => "INPUT_OBJECT", + "name" => "Complex" + }, + "defaultValue" => nil, + "description" => nil, + "name" => "complex" + } + ] + } + ) + end) + end + end + describe "introspection of an enum type" do test "can use __type and value information with deprecations" do result =