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

fix: Remove to_graphql and make the interpreter runtime a requirement for older GraphQL versions #177

Merged
merged 5 commits into from
Mar 8, 2022

Conversation

daemonsy
Copy link
Contributor

@daemonsy daemonsy commented Mar 7, 2022

What's up?

Trying to deal with the problem caused by to_graphql in #151.

The cause

GraphQL Ruby is deprecating the to_graphql method, slated for removal in 2.0. In 1.13, an argument was introduced def to_graphql(silence_deprecation_warning: false).

We have a to_graphql method in our codebase to add federation directives decorations. It is breaking because we defined it as a method with no arguments.

Tests didn't break because we don't actually call this method in our specs. We rely on GraphQL ruby to call it in GraphQL versions where the interpreter runtime is not the default.

Complications

First thought was to add a spec to it, proxy arguments over. I'm used to proxying args Ruby 2.7.x style. It failed in our specs because the specs are running on Ruby 2.6.x. See this article.

Given that Ruby 3.x is out, our keyword proxying should do the right thing. We also really didn't want to check for arity.

Let's just remove to_graphql

Specs fail if we remove the method, but why? The library requires the call to populate metadata on the legacy runtime.

If we made the interpreter runtime a requirement on older versions of GraphQL where it wasn't the default, all specs pass.

Given how old these versions are, I think this is the best solution. We're going to remove its use for 2.0 anyway.

@daemonsy daemonsy changed the title fix: proxy arguments on to_graphql + spec for it fix: Remove use of to_graphql and make the interpreter runtime a requirement Mar 8, 2022
@@ -58,6 +58,11 @@ def top_products(first:)
end

class ProductSchema < GraphQL::Schema
if Gem::Version.new(GraphQL::VERSION) < Gem::Version.new('1.12.0')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the other test schemas already have this code block, these two just happened to be missed 🤷‍♂️

@@ -293,8 +293,9 @@ See discussion at [#74](https://github.com/Gusto/apollo-federation-ruby/issues/7

## Known Issues and Limitations

- Only works with class-based schemas, the legacy `.define` API will not be supported
- Does not add directives to the output of `Schema.to_definition`. Since `graphql-ruby` doesn't natively support schema directives, the directives will only be visible to the [Apollo Gateway](https://www.apollographql.com/docs/apollo-server/api/apollo-gateway/) through the `Query._service` field (see the [Apollo Federation specification](https://www.apollographql.com/docs/apollo-server/federation/federation-spec/)) or via [`Schema#federation_sdl`](https://github.com/Gusto/apollo-federation-ruby/blob/1d3baf4f8efcd02e7bf5bc7e3fee5b4fb963cd25/lib/apollo-federation/schema.rb#L19) as explained above.
- For GraphQL older than 1.12, the interpreter runtime has to be used.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should try to do a check in when the federation module is included. Given how old these versions are, I thought it wasn't necessary.

@daemonsy daemonsy requested review from geshwho and grxy March 8, 2022 15:23
@daemonsy daemonsy changed the title fix: Remove use of to_graphql and make the interpreter runtime a requirement fix: Remove to_graphql and make the interpreter runtime a requirement for older GraphQL versions Mar 8, 2022
@daemonsy
Copy link
Contributor Author

daemonsy commented Mar 8, 2022

I'd think we can remove support for GraphQL < 1.12 once we support 2.0. But I'd like to get some stats first if I can to confirm that they're not widely used by the community.

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.

LGTM

@daemonsy daemonsy merged commit bfc3082 into main Mar 8, 2022
@daemonsy daemonsy deleted the to_graphql_spec branch March 8, 2022 17:30
rylanc pushed a commit that referenced this pull request Mar 8, 2022
## [2.2.1](v2.2.0...v2.2.1) (2022-03-08)

### Bug Fixes

* Remove to_graphql and make the interpreter runtime a requirement for older GraphQL versions ([#177](#177)) ([bfc3082](bfc3082))
@rylanc
Copy link
Contributor

rylanc commented Mar 8, 2022

🎉 This PR is included in version 2.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants