diff --git a/lib/absinthe/federation/schema/prototype/federated_directives.ex b/lib/absinthe/federation/schema/prototype/federated_directives.ex index 1530268..6d7cf34 100644 --- a/lib/absinthe/federation/schema/prototype/federated_directives.ex +++ b/lib/absinthe/federation/schema/prototype/federated_directives.ex @@ -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 diff --git a/test/absinthe/federation/notation_test.exs b/test/absinthe/federation/notation_test.exs index c85e820..7d94cb2 100644 --- a/test/absinthe/federation/notation_test.exs +++ b/test/absinthe/federation/notation_test.exs @@ -121,5 +121,41 @@ 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 valid" do + defmodule ComposePrototype do + use Absinthe.Schema.Prototype + use Absinthe.Federation.Schema.Prototype.FederatedDirectives + + directive :custom do + on :schema + end + + directive :other 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