Skip to content

Commit

Permalink
Remove federated types when rendering SDL (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdawgwilk authored Mar 31, 2022
1 parent 0ae55a6 commit b35776e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
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

0 comments on commit b35776e

Please sign in to comment.