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: Optionally underscore _Any keys #248

Merged
merged 4 commits into from
Jun 2, 2023

Conversation

jturkel
Copy link
Contributor

@jturkel jturkel commented May 24, 2023

This PR adds optional support to underscore the keys in the _Any scalar for consistency with the fields argument of the ApolloFederation::Object.key method and graphql-ruby's general conversion from camelcase to snakecase. I disabled this by default for backwards compatibility but it should probably be enabled by default in the next major release.

@grxy
Copy link
Collaborator

grxy commented May 26, 2023

@jturkel Thanks for the PR. This could lead to a big migration for large projects. Is there any way we could make this adoptable on a per-entity basis?

@jturkel
Copy link
Contributor Author

jturkel commented May 27, 2023

@grxy - That's a fair concern. What about an underscore_reference_keys DSL method on ApolloFederation::Object that lets individual entities opt into this behavior e.g.

class User < BaseObject
  underscore_reference_keys true

  def self.resolve_reference(reference, context)
    USERS.find { |user| user[:my_id] == reference[:my_id] }
  end
end

This would also allow applications to opt into this behavior for all entities via a BaseObject superclass:

class BaseObject < GraphQL::Schema::Object
  include ApolloFederation::Object

  field_class BaseField
  underscore_reference_keys true
end

@grxy
Copy link
Collaborator

grxy commented May 30, 2023

@jturkel I think that approach makes a lot more sense since it allows both incremental and all-at-once adoption. We can talk about it in the future, but we can probably make that behavior the default in a future major release, for consistency with GraphQL Ruby.

@jturkel
Copy link
Contributor Author

jturkel commented May 30, 2023

@grxy - I switched to using a per-entity setting. Let me know what you think.

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.

This seems almost there. Have a suggestion for documentation, a small implementation detail change, and an additional test request.

lib/apollo-federation/entities_field.rb Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
spec/apollo-federation/entities_field_spec.rb Show resolved Hide resolved
@jturkel jturkel requested a review from grxy June 1, 2023 21:33
@grxy grxy merged commit f1688e7 into Gusto:main Jun 2, 2023
grxy pushed a commit that referenced this pull request Jun 2, 2023
# [3.8.0](v3.7.1...v3.8.0) (2023-06-02)

### Features

* optionally underscore _Any keys ([#248](#248)) ([f1688e7](f1688e7))
@grxy
Copy link
Collaborator

grxy commented Jun 2, 2023

🎉 This PR is included in version 3.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@grxy grxy added the released label Jun 2, 2023
moonflare added a commit to moonflare/apollo-federation-ruby that referenced this pull request Sep 6, 2023
In a previous Pull Request (Gusto#248) there was added support for underscoring the keys and while this covered the `Object` class, it didn't also cover the `Interface` module. This commit adds the same `underscore_reference_keys` method to the `Interface` module.
moonflare added a commit to moonflare/apollo-federation-ruby that referenced this pull request Sep 6, 2023
In a previous Pull Request (Gusto#248) there was added support for underscoring the keys and while this covered the `Object` class, it didn't also cover the `Interface` module. This commit adds the same `underscore_reference_keys` method to the `Interface` module.
moonflare added a commit to moonflare/apollo-federation-ruby that referenced this pull request Sep 7, 2023
In a previous Pull Request (Gusto#248) there was added support for underscoring the keys and while this covered the `Object` class, it didn't also cover the `Interface` module. This commit adds the same `underscore_reference_keys` method to the `Interface` module.
moonflare added a commit to moonflare/apollo-federation-ruby that referenced this pull request Sep 8, 2023
In a previous Pull Request (Gusto#248) there was added support for underscoring the keys and while this covered the `Object` class, it didn't also cover the `Interface` module. This commit adds the same `underscore_reference_keys` method to the `Interface` module.
moonflare added a commit to moonflare/apollo-federation-ruby that referenced this pull request Sep 14, 2023
In a previous Pull Request (Gusto#248) there was added support for underscoring the keys and while this covered the `Object` class, it didn't also cover the `Interface` module. This commit adds the same `underscore_reference_keys` method to the `Interface` module.
Kaytal pushed a commit to lensrentals/apollo-federation-ruby that referenced this pull request Oct 1, 2024
* Optionally underscore _Any keys.

* Switch to per-entity setting

* Apply feedback
Kaytal pushed a commit to lensrentals/apollo-federation-ruby that referenced this pull request Oct 1, 2024
# [3.8.0](Gusto/apollo-federation-ruby@v3.7.1...v3.8.0) (2023-06-02)

### Features

* optionally underscore _Any keys ([Gusto#248](Gusto#248)) ([f1688e7](Gusto@f1688e7))
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.

2 participants