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

Remove federated types when rendering SDL #42

Merged
merged 1 commit into from
Mar 31, 2022
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
13 changes: 5 additions & 8 deletions lib/absinthe/federation/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ defmodule Absinthe.Federation.Schema do
|> Absinthe.Pipeline.for_schema(prototype_schema: schema.__absinthe_prototype_schema__())
|> Absinthe.Pipeline.upto({Absinthe.Phase.Schema.Validation.Result, pass: :final})
|> Absinthe.Schema.apply_modifiers(schema)

# TODO: Due to an issue found with rendering the SDL we had to revert this functionality
# https://github.com/DivvyPayHQ/absinthe_federation/issues/28
# |> Absinthe.Pipeline.without(__MODULE__.Phase.AddFederatedTypes)
# |> Absinthe.Pipeline.insert_before(
# Absinthe.Phase.Schema.ApplyDeclaration,
# __MODULE__.Phase.RemoveResolveReferenceFields
# )
|> Absinthe.Pipeline.without(__MODULE__.Phase.AddFederatedTypes)
|> Absinthe.Pipeline.insert_before(
Absinthe.Phase.Schema.ApplyDeclaration,
__MODULE__.Phase.RemoveResolveReferenceFields
)
end

@spec to_federated_sdl(schema :: Absinthe.Schema.t()) :: String.t()
Expand Down
12 changes: 11 additions & 1 deletion lib/absinthe/federation/schema/phase/add_federated_directives.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ defmodule Absinthe.Federation.Schema.Phase.AddFederatedDirectives do
defp maybe_add_key_directive(node, %{key_fields: fields}) when is_binary(fields) do
directive = Directive.build("key", fields: fields)

add_directive(node, directive)
node
|> add_directive(directive)
|> mark_referenced()
end

defp maybe_add_key_directive(node, %{key_fields: fields}) when is_list(fields) do
fields
|> Enum.map(&Directive.build("key", fields: &1))
|> Enum.reduce(node, &add_directive(&2, &1))
|> mark_referenced()
end

defp maybe_add_key_directive(node, _meta), do: node
Expand Down Expand Up @@ -83,4 +86,11 @@ defmodule Absinthe.Federation.Schema.Phase.AddFederatedDirectives do
end

defp add_directive(node, _directive), do: node

defp mark_referenced(%{__private__: private} = node) do
new_private = Keyword.put(private, :__absinthe_referenced__, true)
%{node | __private__: new_private}
end

defp mark_referenced(node), do: node
end
3 changes: 0 additions & 3 deletions test/absinthe/federation/schema/service_field_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ defmodule Absinthe.Federation.Schema.ServiceFieldTest do
assert sdl =~ "@key(fields: \"email\")"
end

# TODO: Due to an issue found with rendering the SDL we had to revert this functionality
# https://github.com/DivvyPayHQ/absinthe_federation/issues/28
@tag :skip
test "returns sdl with federated types/fields removed" do
query = """
{
Expand Down
3 changes: 0 additions & 3 deletions test/absinthe/federation/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ defmodule Absinthe.Federation.SchemaTest do
assert sdl =~ "type User @extends @key(fields: \"id\") {"
end

# TODO: Due to an issue found with rendering the SDL we had to revert this functionality
# https://github.com/DivvyPayHQ/absinthe_federation/issues/28
@tag :skip
test "does not render federated types" do
sdl = Absinthe.Federation.to_federated_sdl(TestSchema)

Expand Down