Skip to content

Commit

Permalink
Merge pull request #1186 from maartenvanvliet/mark-root-objects-refer…
Browse files Browse the repository at this point in the history
…enced

Ensure root objects are marked as referenced correctly
  • Loading branch information
benwilson512 authored Aug 30, 2022
2 parents 3a6b053 + 8dc22a5 commit c887273
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
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

0 comments on commit c887273

Please sign in to comment.