apollo-federation 3.7.1 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4104a6574a535d062fe70d793bfa1b3c9099adfc8a1ecc5eeed79d296f1386b
4
- data.tar.gz: d459803bca66e82aa00dc93c86efd63740a5e5531b33b18419bb246846d10a52
3
+ metadata.gz: ea55be797646c3f816a4f83e134bed0fd3cf3ee1cd7ce30cda45e88513385a75
4
+ data.tar.gz: 271cb2c2d084ae1499e1974de9d06035701a4d356781a0a7cfc49bf4c0eb88d4
5
5
  SHA512:
6
- metadata.gz: 64ae19c9756916d3157158866f3a44cfc75644bba283aa9143237ba644c9ea2ffd6e0c91ca17dc558414a61867d04bbe8f379fee3d0a28f1f0b66298d1fb6e5d
7
- data.tar.gz: 8c7789e315d9e68bf0c3fb1711c9a6463611bb335cfd970be5eb989a7c6ebf92c15ece86464670301e43c6978d7cb5eae3161a9841f40f0e278e0a7cba234f1f
6
+ metadata.gz: 58f93ab4cb85ddac1f2e537dd83d25e9fe88e174c43c4c7d864ee6e2b16858d510dd79f36b246ac6bfda27bef7a940ea2840c414f613ca92e5bb7d63f1cec9b1
7
+ data.tar.gz: 36f9fd3a2259508d896d8bb42f0e187bacfe628bcfdf8d88ac1effc10f62bf465da5c4a6ff38dd5c682527cf1c710becd6f8c5c2d27c6883801b396b04d55725
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [3.8.0](https://github.com/Gusto/apollo-federation-ruby/compare/v3.7.1...v3.8.0) (2023-06-02)
2
+
3
+
4
+ ### Features
5
+
6
+ * optionally underscore _Any keys ([#248](https://github.com/Gusto/apollo-federation-ruby/issues/248)) ([f1688e7](https://github.com/Gusto/apollo-federation-ruby/commit/f1688e793ba08195a06ddad74d84f2858dcdfcdf))
7
+
1
8
  ## [3.7.1](https://github.com/Gusto/apollo-federation-ruby/compare/v3.7.0...v3.7.1) (2023-06-01)
2
9
 
3
10
 
data/README.md CHANGED
@@ -325,12 +325,39 @@ Define a `resolve_reference` class method on your object. The method will be pas
325
325
 
326
326
  ```ruby
327
327
  class User < BaseObject
328
+ key fields: :user_id
329
+ field :user_id, ID, null: false
330
+
328
331
  def self.resolve_reference(reference, context)
329
- USERS.find { |user| user[:id] == reference[:id] }
332
+ USERS.find { |user| user[:userId] == reference[:userId] }
330
333
  end
331
334
  end
332
335
  ```
333
336
 
337
+ To maintain backwards compatibility, by default, reference hash keys are camelcase. They can be underscored by setting `underscore_reference_keys` on your entity class. In order to maintain consistency with GraphQL Ruby, we may change the keys to be underscored by default in a future major release.
338
+
339
+ ```ruby
340
+ class User < BaseObject
341
+ key fields: :user_id
342
+ field :user_id, ID, null: false
343
+ underscore_reference_keys true
344
+
345
+ def self.resolve_reference(reference, context)
346
+ USERS.find { |user| user[:user_id] == reference[:user_id] }
347
+ end
348
+ end
349
+ ```
350
+ Alternatively you can change the default for your project by setting `underscore_reference_keys` on `BaseObject`:
351
+
352
+ ```ruby
353
+ class BaseObject < GraphQL::Schema::Object
354
+ include ApolloFederation::Object
355
+
356
+ field_class BaseField
357
+ underscore_reference_keys true
358
+ end
359
+ ```
360
+
334
361
  ### Tracing
335
362
 
336
363
  To support [federated tracing](https://www.apollographql.com/docs/apollo-server/federation/metrics/):
@@ -49,6 +49,14 @@ module ApolloFederation
49
49
  # TODO: What if the type is an interface?
50
50
  type_class = class_of_type(type)
51
51
 
52
+ if type_class.underscore_reference_keys
53
+ references.map! do |reference|
54
+ reference.transform_keys do |key|
55
+ GraphQL::Schema::Member::BuildType.underscore(key.to_s).to_sym
56
+ end
57
+ end
58
+ end
59
+
52
60
  if type_class.respond_to?(:resolve_references)
53
61
  results = type_class.resolve_references(references, context)
54
62
  elsif type_class.respond_to?(:resolve_reference)
@@ -43,6 +43,18 @@ module ApolloFederation
43
43
  arguments: arguments,
44
44
  )
45
45
  end
46
+
47
+ def underscore_reference_keys(value = nil)
48
+ if value.nil?
49
+ if @underscore_reference_keys.nil?
50
+ find_inherited_value(:underscore_reference_keys, false)
51
+ else
52
+ @underscore_reference_keys
53
+ end
54
+ else
55
+ @underscore_reference_keys = value
56
+ end
57
+ end
46
58
  end
47
59
  end
48
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApolloFederation
4
- VERSION = '3.7.1'
4
+ VERSION = '3.8.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apollo-federation
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.1
4
+ version: 3.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noa Elad
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-06-01 00:00:00.000000000 Z
12
+ date: 2023-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql