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

Cannot use different aliases for @inaccessible in subgraphs #1976

Open
lennyburdette opened this issue Jul 12, 2022 · 2 comments
Open

Cannot use different aliases for @inaccessible in subgraphs #1976

lennyburdette opened this issue Jul 12, 2022 · 2 comments
Assignees

Comments

@lennyburdette
Copy link
Contributor

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
Copy link
Contributor Author

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.)

@prasek
Copy link
Contributor

prasek commented Jul 14, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants