-
Notifications
You must be signed in to change notification settings - Fork 79
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
feat: Support Federation v2 #196
Conversation
Oops! I didn't realise `Hash#except` was only available from Ruby 3.0
…hack!) See: https://www.apollographql.com/docs/federation/federation-2/moving-to-federation-2/#opt-in-to-federation-2 This is a horrible hack. Need to figure out if there is a clean way of including this in the document and the printer output.
👍 Seems like it should do the job! The only new feature I read about but didn't see in the tests was |
Hey @col thanks for submitting this. 👏. I personally haven't caught up with the changes in Federation V2. We should be able to put some focus on this in mid month. Meanwhile, @lennyburdette if you're around, be nice to get some thoughts from you on this PR. |
This is great, thanks for putting this together! I'd like to make one suggestion: can there be a way to explicitly opt-in to Federation 2 (so that it adds the A common workflow for converting a subgraph to Federation 2 looks like this:
The rules around shareable types and fields and the Otherwise, I think the code is sound and I'm excited to see this land! |
This is more explicit and extendable in the future if we ever need any other federation options at the schema level
Good suggestion @lennyburdette! I was never very happy with my initial approach of searching for usages of the v2 directives. I've opted for the version to be a keyword arg so that we can add other options in the future if required.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking forward to seeing this land!
lib/apollo-federation/schema.rb
Outdated
FEDERATION_2_PREFIX = <<~SCHEMA | ||
extend schema | ||
@link(url: "https://specs.apollo.dev/federation/v2.0", | ||
import: ["@key", "@extends", "@external", "@requires", "@provides", "@shareable", "@inaccessible", "@override"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's importing all of the directives unconditionally. Is that acceptable, or should it be more dynamic to only import the directives that are actually used in the schema?
Apollo docs say "Modify the import array to include whichever federated directives your subgraph schema uses."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is @extends
a valid directive in this context? I don't see it in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One subtle feature of the @link
spec is that you don't have to import these directives. If you don't supply the import:
argument, the directives are still available in a namespaced form:
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0")
type Foo @federation__key(fields: "bar") @federation__shareable {
bar: ID!
baz: String @federation__external
quux: String @federation__requires(fields: "bax")
blah: String @federation__inaccesible
}
This might be the "right" approach for a code-first library. The key
ruby method could output @federation__key
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yes, I believe the @extends
directive was dropped entirely in Fed 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @extends
is still optionally supported. We either need to support @extends
or have proper support for type extensions (eg. extend type
).
See: https://www.apollographql.com/docs/federation/federation-spec/#federation-schema-specification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have an example problem scenario, no. I honestly don't know what impact importing all of the directives might have. I suppose there's a possibility that a Graph has already defined directives with the same names, and those could be in conflict with the Apollo Federation directives -- thus an author might need to use the namespaced directives to work around that. Is that a realistic scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs for the @link directive cover the namespacing feature, which is actually configurable using as:
. I'm inclined to agree with @lennyburdette on the preference to use the namespaced directives in this implementation, and thus avoid the need to specify the directives in the @link
declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out the spec—that's exactly where the import:
behavior is documented. Here's what the federation team says about using import or not:
you can absolutely skip any import and use @federation__key and I can see many code-first libraries doing just that since it’s probably a bit simpler (no worries about name conflicts, etc…).
...
if it matters to you that the SDL you generate is as readable as possible, then using the import makes sense.
The only benefit to not using import and emitting the namespaced directives is that it would allow graph authors to use the shorter directive names for their own purposes. But you could also support that with a DSL for emitting import: [{ name: "@tag", as: "@mytag" }]
so you're not painted into a corner if you choose the short names today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way this is done currently, @lennyburdette , does it pass the @link
test in https://www.apollographql.com/docs/federation/other-servers/?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this should be sufficient. The test is rudimentary right now: it just searches the _Service.sdl
for the presence of "@link": https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/main/src/tests/link.test.ts
Hi @col @lyricsboy @lennyburdette thanks for all the work and comments on the PR so far. @geshwho and I paired over reviewing the 2.0 spec and the PR. Overall the PR looks great! Jotting down a few notes: Code considerations
Proposed ops for shipping
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Thanks for adding 2.0 support to the library. Just some general code comments in this review.
I'll take the feature branch out for a spin with our main app later today.
README.md
Outdated
```ruby | ||
class MySchema < GraphQL::Schema | ||
include ApolloFederation::Schema | ||
federation version: 2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might this be the place to support import
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
version:
should probably be a string. we don't foresee a need for 2.0.1
but it's possible
lib/apollo-federation/schema.rb
Outdated
FEDERATION_2_PREFIX = <<~SCHEMA | ||
extend schema | ||
@link(url: "https://specs.apollo.dev/federation/v2.0", | ||
import: ["@key", "@extends", "@external", "@requires", "@provides", "@shareable", "@inaccessible", "@override"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way this is done currently, @lennyburdette , does it pass the @link
test in https://www.apollographql.com/docs/federation/other-servers/?
FYI I spoke with the maintainer of graphql-kotlin (another code-first graphql library) and I think we're settled on emitting only namespaced directives ( |
Thanks @lennyburdette ! |
Hi @col are you still actively working on this PR? No worries if you're not able to, we can merge the existing work and do some of the action items separately. |
I'm happy to incorporate some of the feedback and update the PR over the next day or two. |
This approach feel a little easier to understand
@daemonsy (CC: @lennyburdette @lyricsboy) I've updated the PR with your feedback. Please take another look. Changes:
|
Hey @col it's looking good to me. I am going to run some sanity check on the PR using our codebase. @lennyburdette how does it look to you? |
looks great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Just a couple grammar nits.
Thanks for putting this together!
@daemonsy Any update? Can't wait to use this feature 😅 👏 |
Thanks for working on this @col and your patience in getting the PR through 👏 |
# [3.1.0](v3.0.0...v3.1.0) (2022-06-21) ### Features * Support Federation v2 ([#196](#196)) ([238736c](238736c)), closes [/www.apollographql.com/docs/federation/federation-2/moving-to-federation-2/#opt-in-to-federation-2](https://github.com//www.apollographql.com/docs/federation/federation-2/moving-to-federation-2//issues/opt-in-to-federation-2)
🎉 This PR is included in version 3.1.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This PR adds support for the @sharable, @inaccessible and @OverRide directives. I believe this is all that is required to support Apollo Federation v2.0.
Issue: #153
Original PR #195 was closed due to branch rename.