federation icon indicating copy to clipboard operation
federation copied to clipboard

Cannot use different aliases for @inaccessible in subgraphs

Open lennyburdette opened this issue 3 years ago • 2 comments

Reproduction: https://stackblitz.com/edit/basic-federation-wcgoqe?file=one.js,two.js

This was brought up in the apollo-federation-ruby repo.

You can mix and match import aliases for @key and @shareable, but if you use import: ["@inaccessible"] in one subgraph and @federation__inaccessible in another subgraph, you get this error:

The federation "@inaccessible" directive is imported with mismatched name between subgraphs: it is imported as "@federation__inaccessible" in subgraph "TWO" but "@inaccessible" in subgraph "ONE"

From this code, it appears to be a problem with @tag too:

https://github.com/apollographql/federation/blob/main/composition-js/src/merging/merge.ts#L198-L201 https://github.com/apollographql/federation/blob/main/composition-js/src/merging/merge.ts#L285-L287 https://github.com/apollographql/federation/blob/main/composition-js/src/merging/merge.ts#L292-L322

Expected result Subgraphs should be able to import all federation directives however they like and be compatible with each other in composition.

lennyburdette avatar Jul 12 '22 13:07 lennyburdette

Summarizing conversations elsewhere:

Allowing different subgraphs to use different aliases for tag and inaccessible is a little bit awkward because they end up in the supergraph—which alias should we use?

But! Tag and inaccessible in subgraphs are actually different from tag/inaccessible in supergraphs. They're conceptually similar but they actually come from different core features:

# in subgraphs
@link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@inaccessible", "@tag"])

# in supergraphs
@link(url: "https://specs.apollo.dev/inaccessible/v0.2", for: SECURITY)
@link(url: "https://specs.apollo.dev/tag/v0.2")

So I think that it should work like this:

  • Composition can match tag and inaccessible in subgraphs regardless of how they're aliased.
  • Composition only emits @inaccessible and @tag (from the other core features) in the supergraph regardless of how they're used in subgraphs.

It's worth mentioning that this is related but not the same problem as merging arbitrary directives. When we support something like

extend schema
        @link(url: "https://specs.apollo.dev/foo/v1.0", import: [{ name: "@foo", as: "@myfoo" }])
        @composeDirective(name: "@myfoo")

then expected subgraphs to agree upon the name so that it's clear what the name will be in the supergraph is a reasonable expectation. (And adding a post-composition transformation to change to name is a future possibility.)

lennyburdette avatar Jul 12 '22 17:07 lennyburdette

we don't currently support using different aliases across subgraphs for composed directives like @tag and @inaccessible, and this is something we'll fix in the future as we tackle the larger namespacing issues, but not in the immediate future. For now all subgraph libraries should import @tag and @inaccessible and not use @federation__tag or @federation__inaccessible.

@jeffjakub the https://www.apollographql.com/docs/federation/federation-spec needs to be updated to reflect this for @tag and @inaccessible and @hwillson make sure the https://github.com/apollographql/apollo-federation-subgraph-compatibility are updated to reflect this as well, thx!

prasek avatar Jul 14 '22 14:07 prasek