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

Add composeDirective directive, fixes #72 #91

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 13 additions & 0 deletions lib/absinthe/federation/schema/prototype/federated_directives.ex
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ defmodule Absinthe.Federation.Schema.Prototype.FederatedDirectives do
:input_field_definition
]
end

@desc """
Indicates to composition that all uses of a particular custom type system directive in the subgraph schema should
be preserved in the supergraph schema.

See [Apollo Federation docs](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#managing-custom-directives)
for details.
"""
directive :compose_directive do
arg :name, non_null(:string)
repeatable true
on [:schema]
end
end
end
end
32 changes: 32 additions & 0 deletions test/absinthe/federation/notation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,37 @@ defmodule Absinthe.Federation.NotationTest do
assert sdl =~
~s(schema @link(url: "https:\\/\\/myspecs.example.org\\/myDirective\\/v1.0", import: ["@myDirective"]\) @link(url: "https:\\/\\/specs.apollo.dev\\/federation\\/v2.0", import: ["@key", "@tag"]\))
end

test "schema with multiple composeDirectives is valiad" do
defmodule ComposePrototype do
use Absinthe.Schema.Prototype
use Absinthe.Federation.Schema.Prototype.FederatedDirectives

directive :custom do
on :schema
end
end

defmodule MultipleComposeDirectivesSchema do
use Absinthe.Schema
use Absinthe.Federation.Schema, skip_prototype: true

@prototype_schema ComposePrototype

extend schema do
directive :link, url: "https://specs.apollo.dev/federation/v2.1", import: ["@composeDirective"]
directive :composeDirective, name: "@custom"
directive :composeDirective, name: "@other"
end

query do
field :hello, :string
end
end

sdl = Absinthe.Schema.to_sdl(MultipleComposeDirectivesSchema)

assert sdl =~ ~s{schema @composeDirective(name: "@other") @composeDirective(name: "@custom")}
end
end
end
Loading