apollo-federation 2.0.1 → 2.2.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: 8a8a1aec191839f10fc35c1184f6d8c8a1a307dff82ba96a159ef5e140260ba0
4
- data.tar.gz: fb9ae5a4a02e97973d4a107050f8190a9f22dbe90ca26017ce7d528f80440965
3
+ metadata.gz: 8c7f0082fb2aa33917e92171264675d2ac09cbce6b88a4f8cbcf78a0ba87c85e
4
+ data.tar.gz: e4a21a9eb9866c43c25dd799b032e296a115cbda7e48fdc49dfa4695b7bafb4e
5
5
  SHA512:
6
- metadata.gz: 3f920513b88d57be072ed9348b9ebea3054c16c9c137f38b30174e6d5d4c768a35f781c7129546f37603563e123486df3782fb51c1fb96cde65a8fa464b8cb5d
7
- data.tar.gz: 18de702e8ddc5b0173369cd8b106a95c7d14ff929d31f91fc3ae7c758fcecd1ab3c0f4e9425d712b3c07e7dbad70c6407d60f0dcd6448cc6708d453490e49cc2
6
+ metadata.gz: fa0445989376adf48a2f32af007bc05522f4d404b43dba8fefb542e8bc2700c83f59a931e9cb15fae2d0e30c68b99fa9e33c1c3e05e562f84b455563ed78fc5d
7
+ data.tar.gz: 5d4f7b51e6115e92b9aa89b5c59b68e9442867d653381823929c2c16a2ec9c51a74746d5c81092dfb5bfe7d3f56710462c3785b0279593752ceb0577b6237aa6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ # [2.2.0](https://github.com/Gusto/apollo-federation-ruby/compare/v2.1.0...v2.2.0) (2022-02-04)
2
+
3
+
4
+ ### Features
5
+
6
+ * Get Apollo Federation to work with GraphQL 1.13.x ([#160](https://github.com/Gusto/apollo-federation-ruby/issues/160)) ([800001b](https://github.com/Gusto/apollo-federation-ruby/commit/800001baa5a54ab377998c651e7049da254c451b)), closes [#147](https://github.com/Gusto/apollo-federation-ruby/issues/147)
7
+
8
+ # [2.1.0](https://github.com/Gusto/apollo-federation-ruby/compare/v2.0.3...v2.1.0) (2022-02-02)
9
+
10
+
11
+ ### Features
12
+
13
+ * snake case field references ([f5506ae](https://github.com/Gusto/apollo-federation-ruby/commit/f5506aecd10ea0c4a72744be07e0a9ad5cd45b16))
14
+
15
+ ## [2.0.3](https://github.com/Gusto/apollo-federation-ruby/compare/v2.0.2...v2.0.3) (2022-02-02)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * Attempt to remove platform specific lock on google-protobuf ([#171](https://github.com/Gusto/apollo-federation-ruby/issues/171)) ([7898c28](https://github.com/Gusto/apollo-federation-ruby/commit/7898c2851aca06f08fa2559652375769bb98dfd8))
21
+
22
+ ## [2.0.2](https://github.com/Gusto/apollo-federation-ruby/compare/v2.0.1...v2.0.2) (2022-01-31)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * Use `bundle install` to avoid `bundle check` that changes our lockfiles ([#170](https://github.com/Gusto/apollo-federation-ruby/issues/170)) ([5c89ff1](https://github.com/Gusto/apollo-federation-ruby/commit/5c89ff1545dd1e6668fcdcf5b6fa89188cbb3ab4))
28
+
1
29
  ## [2.0.1](https://github.com/Gusto/apollo-federation-ruby/compare/v2.0.0...v2.0.1) (2022-01-27)
2
30
 
3
31
 
data/README.md CHANGED
@@ -105,10 +105,20 @@ Call `key` within your class definition:
105
105
 
106
106
  ```ruby
107
107
  class User < BaseObject
108
- key fields: 'id'
108
+ key fields: :id
109
109
  end
110
110
  ```
111
111
 
112
+ Compound keys are also supported:
113
+
114
+ ```ruby
115
+ class User < BaseObject
116
+ key fields: [:id, { organization: :id }]
117
+ end
118
+ ```
119
+
120
+ See [field set syntax](#field-set-syntax) for more details on the format of the `fields` option.
121
+
112
122
  ### The `@external` directive
113
123
 
114
124
  [Apollo documentation](https://www.apollographql.com/docs/apollo-server/federation/core-concepts/#referencing-external-types)
@@ -131,10 +141,12 @@ Pass the `requires:` option to your field definition:
131
141
  class Product < BaseObject
132
142
  field :price, Int, null: true, external: true
133
143
  field :weight, Int, null: true, external: true
134
- field :shipping_estimate, Int, null: true, requires: { fields: "price weight"}
144
+ field :shipping_estimate, Int, null: true, requires: { fields: [:price, :weight] }
135
145
  end
136
146
  ```
137
147
 
148
+ See [field set syntax](#field-set-syntax) for more details on the format of the `fields` option.
149
+
138
150
  ### The `@provides` directive
139
151
 
140
152
  [Apollo documentation](https://www.apollographql.com/docs/apollo-server/federation/advanced-features/#using-denormalized-data)
@@ -143,9 +155,25 @@ Pass the `provides:` option to your field definition:
143
155
 
144
156
  ```ruby
145
157
  class Review < BaseObject
146
- field :author, 'User', null: true, provides: { fields: 'username' }
158
+ field :author, 'User', null: true, provides: { fields: :username }
147
159
  end
148
160
  ```
161
+ See [field set syntax](#field-set-syntax) for more details on the format of the `fields` option.
162
+
163
+ ### Field set syntax
164
+
165
+ Field sets can be either strings encoded with the Apollo Field Set [syntax]((https://www.apollographql.com/docs/apollo-server/federation/federation-spec/#scalar-_fieldset)) or arrays, hashes and snake case symbols that follow the graphql-ruby conventions:
166
+
167
+ ```ruby
168
+ # Equivalent to the "organizationId" field set
169
+ :organization_id
170
+
171
+ # Equivalent to the "price weight" field set
172
+ [:price, :weight]
173
+
174
+ # Equivalent to the "id organization { id }" field set
175
+ [:id, { organization: :id }]
176
+ ```
149
177
 
150
178
  ### Reference resolvers
151
179
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'apollo-federation/field_set_serializer'
3
4
  require 'apollo-federation/has_directives'
4
5
 
5
6
  module ApolloFederation
@@ -15,7 +16,7 @@ module ApolloFederation
15
16
  name: 'requires',
16
17
  arguments: [
17
18
  name: 'fields',
18
- values: requires[:fields],
19
+ values: ApolloFederation::FieldSetSerializer.serialize(requires[:fields]),
19
20
  ],
20
21
  )
21
22
  end
@@ -24,7 +25,7 @@ module ApolloFederation
24
25
  name: 'provides',
25
26
  arguments: [
26
27
  name: 'fields',
27
- values: provides[:fields],
28
+ values: ApolloFederation::FieldSetSerializer.serialize(provides[:fields]),
28
29
  ],
29
30
  )
30
31
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'graphql'
4
+
5
+ module ApolloFederation
6
+ module FieldSetSerializer
7
+ extend self
8
+
9
+ def serialize(fields)
10
+ case fields
11
+ when Hash
12
+ fields.map do |field, nested_selections|
13
+ "#{camelize(field)} { #{serialize(nested_selections)} }"
14
+ end.join(' ')
15
+ when Array
16
+ fields.map do |field|
17
+ serialize(field)
18
+ end.join(' ')
19
+ when String
20
+ fields
21
+ when Symbol
22
+ camelize(fields)
23
+ else
24
+ raise ArgumentError, "Unexpected field set type: #{fields.class}"
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def camelize(field)
31
+ GraphQL::Schema::Member::BuildType.camelize(field.to_s)
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'apollo-federation/field_set_serializer'
3
4
  require 'apollo-federation/has_directives'
4
5
 
5
6
  module ApolloFederation
@@ -22,7 +23,7 @@ module ApolloFederation
22
23
  name: 'key',
23
24
  arguments: [
24
25
  name: 'fields',
25
- values: fields,
26
+ values: ApolloFederation::FieldSetSerializer.serialize(fields),
26
27
  ],
27
28
  )
28
29
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'apollo-federation/field_set_serializer'
3
4
  require 'apollo-federation/has_directives'
4
5
 
5
6
  module ApolloFederation
@@ -20,7 +21,7 @@ module ApolloFederation
20
21
  name: 'key',
21
22
  arguments: [
22
23
  name: 'fields',
23
- values: fields,
24
+ values: ApolloFederation::FieldSetSerializer.serialize(fields),
24
25
  ],
25
26
  )
26
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApolloFederation
4
- VERSION = '2.0.1'
4
+ VERSION = '2.2.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: 2.0.1
4
+ version: 2.2.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: 2022-01-27 00:00:00.000000000 Z
12
+ date: 2022-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql
@@ -198,6 +198,7 @@ files:
198
198
  - lib/apollo-federation/entity.rb
199
199
  - lib/apollo-federation/federated_document_from_schema_definition.rb
200
200
  - lib/apollo-federation/field.rb
201
+ - lib/apollo-federation/field_set_serializer.rb
201
202
  - lib/apollo-federation/has_directives.rb
202
203
  - lib/apollo-federation/interface.rb
203
204
  - lib/apollo-federation/object.rb