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

feat: add support for @composeDirective #253

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

utay
Copy link

@utay utay commented Jun 16, 2023

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 change link -> default_link_namespace in the federation function because I felt like it makes more sense like this. Happy to hear your thoughts!

@utay utay changed the title Add support for @composeDirective feat: add support for @composeDirective Jun 16, 2023
@utay
Copy link
Author

utay commented Jun 16, 2023

CI fails on graphql-ruby <= 1.11, it looks like schema directives support was added in 1.12:

  1) ApolloFederation::ServiceField with older versions of GraphQL and the interpreter runtime behaves like service field returns the federation SDL with compose directives for the schema
     Failure/Error: super(*args, **kwargs, &block)
     
     ArgumentError:
       unknown keyword: :directives

@grxy
Copy link
Collaborator

grxy commented Jun 20, 2023

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

Copy link
Collaborator

@grxy grxy left a 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:

  1. I'm not understanding the need to support multiple links here. Can we not use @composeDirective with a directive defined in our schema itself?
  2. 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 } }
Copy link
Collaborator

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:

  1. Drop support for GraphQL Ruby < 1.12 (or maybe even < 2.0)
  2. 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.

Copy link
Author

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?

Copy link
Collaborator

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.

Copy link
Author

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

Copy link
Collaborator

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

@@ -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?
Copy link
Collaborator

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.

Copy link
Author

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],
Copy link
Collaborator

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.

Copy link
Author

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|
Copy link
Collaborator

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?

Copy link
Author

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

Copy link
Author

@utay utay left a 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 } }
Copy link
Author

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?

@@ -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?
Copy link
Author

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

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

@utay utay requested a review from grxy August 1, 2023 10:08
@grxy grxy removed their request for review October 16, 2023 19:34
Copy link

@sofie-c sofie-c left a 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.

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

Successfully merging this pull request may close these issues.

support @composeDirective
3 participants