diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dbb24e3cd..ea39daa1a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Bug Fix: [Fix bug in Schema.**absinthe_types**(:all) for Persistent Term](https://github.com/absinthe-graphql/absinthe/pull/1161) - Feature: [Add `import_directives` macro](https://github.com/absinthe-graphql/absinthe/pull/1158) - Feature: [Support type extensions on schema declarations](https://github.com/absinthe-graphql/absinthe/pull/1176) +- Bug Fix: [Root objects are marked as referenced correctly](https://github.com/absinthe-graphql/absinthe/pull/1186) ## 1.7.0 diff --git a/lib/absinthe/phase/schema/mark_referenced.ex b/lib/absinthe/phase/schema/mark_referenced.ex index f009252796..ae1d2bfe65 100644 --- a/lib/absinthe/phase/schema/mark_referenced.ex +++ b/lib/absinthe/phase/schema/mark_referenced.ex @@ -9,13 +9,16 @@ defmodule Absinthe.Phase.Schema.MarkReferenced do %{schema_definitions: [schema]} = blueprint schema = - Map.update!(schema, :type_definitions, &mark_referenced(&1, schema.directive_definitions)) + Map.update!( + schema, + :type_definitions, + &mark_referenced(&1, schema.directive_definitions, schema.schema_declaration) + ) {:ok, %{blueprint | schema_definitions: [schema]}} end - @roots [:query, :mutation, :subscription] - defp mark_referenced(type_defs, directive_defs) do + defp mark_referenced(type_defs, directive_defs, schema_declaration) do types_by_ref = Enum.reduce(type_defs, %{}, fn type_def, acc -> acc @@ -24,8 +27,8 @@ defmodule Absinthe.Phase.Schema.MarkReferenced do end) referenced_type_ids = - @roots - |> Enum.map(&Map.get(types_by_ref, &1)) + schema_declaration.field_definitions + |> Enum.map(&Map.get(types_by_ref, &1.identifier)) |> Enum.reject(&is_nil/1) |> Enum.concat(directive_defs) |> Enum.reduce(MapSet.new(), &referenced_types(&1, types_by_ref, &2)) diff --git a/test/absinthe/schema_test.exs b/test/absinthe/schema_test.exs index ac55d072e8..542178fa13 100644 --- a/test/absinthe/schema_test.exs +++ b/test/absinthe/schema_test.exs @@ -328,10 +328,6 @@ defmodule Absinthe.SchemaTest do name: String } - type MyRootMutation { - name: String - } - type RootQueryType { name(familyName: Boolean): String }