Gusto / apollo-federation-ruby

A Ruby implementation of Apollo Federation
MIT License
216 stars 72 forks source link

feat: Optionally underscore _Any keys #248

Closed jturkel closed 1 year ago

jturkel commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

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

grxy commented 1 year ago

:tada: This PR is included in version 3.8.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: