apollo-federation 2.0.3 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b636d94aed7966b85bb9b0b682fc534b7d1f4ef85b3c81255a4565bbbd779e36
4
- data.tar.gz: 4148abf8ba0f446c63e8fd41b0f77671ec37e1a713968d7c0e9f40e0b4298698
3
+ metadata.gz: fc8de90dc106e25f44e0035a2e7ca3f2a4a37cc9b930d1d245317a93cd54a2f0
4
+ data.tar.gz: ed4a107cde1f0c1e1d4a979d4168de2c248301cf7a7a1250cd868d335fde0828
5
5
  SHA512:
6
- metadata.gz: 5707a70a369a96f0c401bf538969450ef6cb223dca7b0fa62f6d4a9bea4071c0a366122980e9521d9e3d84abf708b1a44151817343389917b5bcffa48dbd32e8
7
- data.tar.gz: dacb441ae9c79f41652d48e472e00bbee4dd947c8aa04f58ec10c3fa8e4eb69216edc62b8685a8119ddd9c4c0050103b893c2b33e26240d94e173c194ae2e660
6
+ metadata.gz: '0214196224a568813ebf0dbb3ca15a81ae902fa06c8c1c1e4fe8f9dba7232f4e0ddbc39275d8cbe8880d415861462813faa2d669d5945d775b68f8bf6ff94e06'
7
+ data.tar.gz: 1690599b1d8c4522cd8ebcca0c001b50b7b40ee8817cb07e0f8220c50bba39c22bdcc50907ca908ead0718989b04df5844fa958aaffb51374fb5ff3b7a8aee56
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [2.2.1](https://github.com/Gusto/apollo-federation-ruby/compare/v2.2.0...v2.2.1) (2022-03-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Remove to_graphql and make the interpreter runtime a requirement for older GraphQL versions ([#177](https://github.com/Gusto/apollo-federation-ruby/issues/177)) ([bfc3082](https://github.com/Gusto/apollo-federation-ruby/commit/bfc308260c34eee04c3b7a5f0e8a0bffe1cb88c4))
7
+
8
+ # [2.2.0](https://github.com/Gusto/apollo-federation-ruby/compare/v2.1.0...v2.2.0) (2022-02-04)
9
+
10
+
11
+ ### Features
12
+
13
+ * 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)
14
+
15
+ # [2.1.0](https://github.com/Gusto/apollo-federation-ruby/compare/v2.0.3...v2.1.0) (2022-02-02)
16
+
17
+
18
+ ### Features
19
+
20
+ * snake case field references ([f5506ae](https://github.com/Gusto/apollo-federation-ruby/commit/f5506aecd10ea0c4a72744be07e0a9ad5cd45b16))
21
+
1
22
  ## [2.0.3](https://github.com/Gusto/apollo-federation-ruby/compare/v2.0.2...v2.0.3) (2022-02-02)
2
23
 
3
24
 
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
 
@@ -265,8 +293,9 @@ See discussion at [#74](https://github.com/Gusto/apollo-federation-ruby/issues/7
265
293
 
266
294
  ## Known Issues and Limitations
267
295
 
268
- - Only works with class-based schemas, the legacy `.define` API will not be supported
269
- - Does not add directives to the output of `Schema.to_definition`. Since `graphql-ruby` doesn't natively support schema directives, the directives will only be visible to the [Apollo Gateway](https://www.apollographql.com/docs/apollo-server/api/apollo-gateway/) through the `Query._service` field (see the [Apollo Federation specification](https://www.apollographql.com/docs/apollo-server/federation/federation-spec/)) or via [`Schema#federation_sdl`](https://github.com/Gusto/apollo-federation-ruby/blob/1d3baf4f8efcd02e7bf5bc7e3fee5b4fb963cd25/lib/apollo-federation/schema.rb#L19) as explained above.
296
+ - For GraphQL older than 1.12, the interpreter runtime has to be used.
297
+ - Does not add directives to the output of `Schema.to_definition`. Since `graphql-ruby` doesn't natively support schema directives, the
298
+ directives will only be visible to the [Apollo Gateway](https://www.apollographql.com/docs/apollo-server/api/apollo-gateway/) through the `Query._service` field (see the [Apollo Federation specification](https://www.apollographql.com/docs/apollo-server/federation/federation-spec/)) or via [`Schema#federation_sdl`](https://github.com/Gusto/apollo-federation-ruby/blob/1d3baf4f8efcd02e7bf5bc7e3fee5b4fb963cd25/lib/apollo-federation/schema.rb#L19) as explained above.
270
299
 
271
300
  ## Maintainers
272
301
 
@@ -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
@@ -8,11 +8,5 @@ module ApolloFederation
8
8
  @federation_directives ||= []
9
9
  @federation_directives << { name: name, arguments: arguments }
10
10
  end
11
-
12
- def to_graphql
13
- field_defn = super # Returns a GraphQL::Field
14
- field_defn.metadata[:federation_directives] = @federation_directives
15
- field_defn
16
- end
17
11
  end
18
12
  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.3'
4
+ VERSION = '2.2.1'
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.3
4
+ version: 2.2.1
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-02-02 00:00:00.000000000 Z
12
+ date: 2022-03-08 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