-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't add _Entity/_entities when no @key types found
- Loading branch information
Showing
6 changed files
with
214 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Absinthe.Federation.Schema.Utils do | ||
@moduledoc false | ||
|
||
alias Absinthe.Blueprint | ||
alias Absinthe.Blueprint.TypeReference.Name | ||
alias Absinthe.Type | ||
|
||
@spec key_field_types(Blueprint.t()) :: list(Blueprint.node_t()) | ||
def key_field_types(blueprint) do | ||
{_blueprint, types} = Blueprint.postwalk(blueprint, [], &collect_key_field_types/2) | ||
|
||
types | ||
end | ||
|
||
defp collect_key_field_types( | ||
%{name: name, __private__: _private} = node, | ||
types | ||
) do | ||
if has_key_directive?(node) do | ||
{node, [%Name{name: name} | types]} | ||
else | ||
{node, types} | ||
end | ||
end | ||
|
||
defp collect_key_field_types(node, acc), do: {node, acc} | ||
|
||
@spec has_key_directive?(struct()) :: boolean() | ||
def has_key_directive?(node) do | ||
meta = Type.meta(node) | ||
has_meta_key = Map.has_key?(meta, :key_fields) | ||
node_directives = Map.get(node, :directives, []) | ||
has_key_directive = Enum.any?(node_directives, &is_key_directive?/1) | ||
has_meta_key or has_key_directive | ||
end | ||
|
||
@spec is_key_directive?(Blueprint.Directive.t()) :: boolean() | ||
def is_key_directive?(%{name: "key"} = _directive), do: true | ||
def is_key_directive?(_directive), do: false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.