-
Notifications
You must be signed in to change notification settings - Fork 77
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: add support for @composeDirective #253
base: main
Are you sure you want to change the base?
Conversation
Add support for @composeDirective
CI fails on graphql-ruby <= 1.11, it looks like schema directives support was added in 1.12:
|
@utay Thanks for putting this together! I will try to take a look this week, but will be OOO for a couple weeks after in the case I'm not able to get to it this week. |
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 have a few concerns with how this is currently written:
- I'm not understanding the need to support multiple links here. Can we not use
@composeDirective
with a directive defined in our schema itself? - I don't think we want to support code paths for multiple federation minor versions. I think we need to clean up the API for defining the version, but
'2.0'
,2.3
,2
, etc. essentially imply the latest 2.x version for now.
query_obj = Class.new(base_object) do | ||
graphql_name 'Query' | ||
|
||
field :product, product, null: true, directives: { complexity_directive => { fixed: 1 } } |
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 this is always going to fail on older GraphQL ruby versions. I think we have a couple options potentially:
- Drop support for GraphQL Ruby < 1.12 (or maybe even < 2.0)
- Only run these tests on newer versions
- If we do this, we should add code to make sure that we warn or raise if composeDirective is used on an older GraphQL Ruby version
I lean towards the first option.
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 like the first option as well. Do you plan to drop support for GraphQL Ruby < 1.12 in a separate PR?
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.
@utay Yeah we'd probably want to do it in a separate PR and publish a new major version.
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.
@grxy Any plan to do that in the near future? It was the main blocker here I think
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.
Hey @utay I'll have to defer to the folks who have taken over maintenance on this gem. CC: @sethc2 @slauppy @sofie-c @simoncoffin
lib/apollo-federation/schema.rb
Outdated
@@ -29,6 +37,10 @@ def federation_2? | |||
Gem::Version.new(federation_version.to_s) >= Gem::Version.new('2.0.0') | |||
end | |||
|
|||
def federation_2_1? |
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 think we should add specific minor version support. We do have some cleanup to do, but it's going to be easier to maintain this lib if we simply aim to support the latest version of federation instead of incrementally supporting minor versions of 2.x. See this issue for more context.
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 see, thanks for the context. I removed this check, mutualized imported directives and fixed tests. I'll wait your call on how we plan to clean up versions
federation version: '2.3', | ||
links: [{ | ||
url: 'https://specs.example.com/federation/v2.3', | ||
import: [complexity_directive.graphql_name], |
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 one probably doesn't need importing with an @link since it is being defined inline.
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.
It looks like even if it's being defined inline it needs to be referenced via a custom link
. For example, if I try to compose a supergraph with an inline directive that isn't imported with link
I get:
UNKNOWN: Directive "@..." in subgraph "..." cannot be composed because it is not a member of a core feature
In the docs they're doing it similarly
federation_namespace = ", as: \"#{link_namespace}\"" if link_namespace != DEFAULT_LINK_NAMESPACE | ||
schema = ['extend schema'] | ||
|
||
all_links.each do |link| |
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 printing logic is fairly complex. Can we make it easier to read?
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.
Tried to do make it easier to read but not a ruby expert, please tell me if there's a better way :)
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.
@grxy Sorry for the delay here and thank you for your review!
query_obj = Class.new(base_object) do | ||
graphql_name 'Query' | ||
|
||
field :product, product, null: true, directives: { complexity_directive => { fixed: 1 } } |
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 like the first option as well. Do you plan to drop support for GraphQL Ruby < 1.12 in a separate PR?
lib/apollo-federation/schema.rb
Outdated
@@ -29,6 +37,10 @@ def federation_2? | |||
Gem::Version.new(federation_version.to_s) >= Gem::Version.new('2.0.0') | |||
end | |||
|
|||
def federation_2_1? |
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 see, thanks for the context. I removed this check, mutualized imported directives and fixed tests. I'll wait your call on how we plan to clean up versions
federation_namespace = ", as: \"#{link_namespace}\"" if link_namespace != DEFAULT_LINK_NAMESPACE | ||
schema = ['extend schema'] | ||
|
||
all_links.each do |link| |
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.
Tried to do make it easier to read but not a ruby expert, please tell me if there's a better way :)
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.
Hi @utay - the team took a look at this yesterday and had some high-level feedback:
- Because this change would require dropping support for other versions of GQL-Ruby, this isn't a trivial lift. We've announced in Development / maintenance status of this gem #267 that we're de-prioritizing these types of changes.
- We'd also like to see some cleanup to this PR before it's in a merge-able state, just around the printing, hard-coding the default link url, etc.
Thank you for taking the time to open this PR and add new functionality. We'd like to eventually support the @composeDirective
but it's something we're de-prioritizing right now.
Fixes #228
This PR adds support for
@composeDirective
as well as having multiple@link
on the schema which is a prerequisite of the former. There's a breaking changelink
->default_link_namespace
in thefederation
function because I felt like it makes more sense like this. Happy to hear your thoughts!