Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure root objects are marked as referenced correctly #1186

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions lib/absinthe/phase/schema/mark_referenced.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
4 changes: 0 additions & 4 deletions test/absinthe/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,6 @@ defmodule Absinthe.SchemaTest do
name: String
}

type MyRootMutation {
name: String
}

type RootQueryType {
name(familyName: Boolean): String
}
Expand Down