apollo-federation 3.7.0 → 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: 7a3acf99a330df8e02ac0217773a9443b400d97a1ad47ed518a2f5631499711f
4
- data.tar.gz: f9482d80b73b9ba0396fc51676a1ab28a12910c6a7fc3b7666421efff705a1ef
3
+ metadata.gz: ea55be797646c3f816a4f83e134bed0fd3cf3ee1cd7ce30cda45e88513385a75
4
+ data.tar.gz: 271cb2c2d084ae1499e1974de9d06035701a4d356781a0a7cfc49bf4c0eb88d4
5
5
  SHA512:
6
- metadata.gz: 10f57a06a03f32dec83f3fbbd293c695a8019914b577b5ae25e6fedd86fa0d0e27be640ccc9261a5fed2f22154535e39d9d9408bfd16cce016ff2bd9cea7beda
7
- data.tar.gz: c7bc892658495ae8576159aa0c14be88837744bfde4dbcd30acb15b443eb817b17400e49f8cd46c59e161ac5975374e84f5405bb30eb8f0280fd80dc2a646f51
6
+ metadata.gz: 58f93ab4cb85ddac1f2e537dd83d25e9fe88e174c43c4c7d864ee6e2b16858d510dd79f36b246ac6bfda27bef7a940ea2840c414f613ca92e5bb7d63f1cec9b1
7
+ data.tar.gz: 36f9fd3a2259508d896d8bb42f0e187bacfe628bcfdf8d88ac1effc10f62bf465da5c4a6ff38dd5c682527cf1c710becd6f8c5c2d27c6883801b396b04d55725
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
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
+
8
+ ## [3.7.1](https://github.com/Gusto/apollo-federation-ruby/compare/v3.7.0...v3.7.1) (2023-06-01)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * handle lazy `resolve_references` return values ([#250](https://github.com/Gusto/apollo-federation-ruby/issues/250)) ([e29b155](https://github.com/Gusto/apollo-federation-ruby/commit/e29b15550d48093c6ed5b73dabb8206a3e9463b0))
14
+ * handle lazy `resolve_references` return values ([#250](https://github.com/Gusto/apollo-federation-ruby/issues/250)) ([1614440](https://github.com/Gusto/apollo-federation-ruby/commit/16144402d32de3d5016023b87fc2b949364761f5))
15
+ * handle lazy resolve_references return values ([#250](https://github.com/Gusto/apollo-federation-ruby/issues/250)) ([fa72465](https://github.com/Gusto/apollo-federation-ruby/commit/fa72465bd5f1d38f3556b748b905f16f932829ac))
16
+
1
17
  # [3.7.0](https://github.com/Gusto/apollo-federation-ruby/compare/v3.6.9...v3.7.0) (2023-05-26)
2
18
 
3
19
 
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/):
@@ -34,7 +34,7 @@ module ApolloFederation
34
34
  .with_index { |r, i| [r, i] }
35
35
  .group_by { |(r, _i)| r[:__typename] }
36
36
 
37
- grouped_references_with_indices.each do |typename, references_with_indices|
37
+ maybe_lazies = grouped_references_with_indices.map do |typename, references_with_indices|
38
38
  references = references_with_indices.map(&:first)
39
39
  indices = references_with_indices.map(&:last)
40
40
 
@@ -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)
@@ -57,21 +65,25 @@ module ApolloFederation
57
65
  results = references
58
66
  end
59
67
 
60
- results_with_indices = results.zip(indices)
61
-
62
- results_with_indices.each do |result, i|
63
- final_result[i] = context.schema.after_lazy(result) do |resolved_value|
64
- # TODO: This isn't 100% correct: if (for some reason) 2 different resolve_reference
65
- # calls return the same object, it might not have the right type
66
- # Right now, apollo-federation just adds a __typename property to the result,
67
- # but I don't really like the idea of modifying the resolved object
68
- context[resolved_value] = type
69
- resolved_value
68
+ context.schema.after_lazy(results) do |resolved_results|
69
+ resolved_results.zip(indices).each do |result, i|
70
+ final_result[i] = context.schema.after_lazy(result) do |resolved_value|
71
+ # TODO: This isn't 100% correct: if (for some reason) 2 different resolve_reference
72
+ # calls return the same object, it might not have the right type
73
+ # Right now, apollo-federation just adds a __typename property to the result,
74
+ # but I don't really like the idea of modifying the resolved object
75
+ context[resolved_value] = type
76
+ resolved_value
77
+ end
70
78
  end
71
79
  end
72
80
  end
73
81
 
74
- final_result
82
+ # Make sure we've resolved the outer level of lazies so we can return an array with a possibly lazy
83
+ # entry for each requested entity
84
+ GraphQL::Execution::Lazy.all(maybe_lazies).then do
85
+ final_result
86
+ end
75
87
  end
76
88
 
77
89
  private
@@ -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.0'
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.0
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-05-26 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