apollo-federation 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +62 -0
- data/lib/apollo-federation/federated_document_from_schema_definition.rb +3 -3
- data/lib/apollo-federation/field.rb +44 -3
- data/lib/apollo-federation/interface.rb +4 -0
- data/lib/apollo-federation/object.rb +8 -0
- data/lib/apollo-federation/schema.rb +22 -1
- data/lib/apollo-federation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c726579bc9db4355491490baae944a9827535beec26b27c7f2800944243f312b
|
4
|
+
data.tar.gz: 578373ded7eecce3f8484530efc7778940605226bf055bc871940266f915ec26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3489a6047e4f225b376adf87a0fa4aad1e0f0c2c34100891df526fea337e75e183e0b3d0a3f63d23881384e9628e0e7ec65f34bc822a610c7285a6c30d6052a8
|
7
|
+
data.tar.gz: be8473595a04f6baa232d7f57c88f0d15a152ce5f8199cdae92b35328032d471545bd0b3d4e5a2cbc91d8a922d5dab9a5afd397f431702d12ad83947bc649fe1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [3.1.0](https://github.com/Gusto/apollo-federation-ruby/compare/v3.0.0...v3.1.0) (2022-06-21)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* Support Federation v2 ([#196](https://github.com/Gusto/apollo-federation-ruby/issues/196)) ([238736c](https://github.com/Gusto/apollo-federation-ruby/commit/238736cdb6f12121ce2a295c7a28fba3990012b9)), closes [/www.apollographql.com/docs/federation/federation-2/moving-to-federation-2/#opt-in-to-federation-2](https://github.com//www.apollographql.com/docs/federation/federation-2/moving-to-federation-2//issues/opt-in-to-federation-2)
|
7
|
+
|
1
8
|
# [3.0.0](https://github.com/Gusto/apollo-federation-ruby/compare/v2.2.4...v3.0.0) (2022-04-05)
|
2
9
|
|
3
10
|
|
data/README.md
CHANGED
@@ -61,6 +61,15 @@ class MySchema < GraphQL::Schema
|
|
61
61
|
end
|
62
62
|
```
|
63
63
|
|
64
|
+
**Optional:** To opt in to Federation v2, specify the version in your schema:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
class MySchema < GraphQL::Schema
|
68
|
+
include ApolloFederation::Schema
|
69
|
+
federation version: '2.0'
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
64
73
|
## Example
|
65
74
|
|
66
75
|
The [`example`](./example/) folder contains a Ruby implementation of Apollo's [`federation-demo`](https://github.com/apollographql/federation-demo). To run it locally, install the Ruby dependencies:
|
@@ -160,6 +169,59 @@ end
|
|
160
169
|
```
|
161
170
|
See [field set syntax](#field-set-syntax) for more details on the format of the `fields` option.
|
162
171
|
|
172
|
+
### The `@shareable` directive (Apollo Federation v2)
|
173
|
+
|
174
|
+
[Apollo documentation](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#shareable)
|
175
|
+
|
176
|
+
Call `shareable` within your class definition:
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
class User < BaseObject
|
180
|
+
shareable
|
181
|
+
end
|
182
|
+
```
|
183
|
+
|
184
|
+
Pass the `shareable: true` option to your field definition:
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
class User < BaseObject
|
188
|
+
field :id, ID, null: false, shareable: true
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
### The `@inaccessible` directive (Apollo Federation v2)
|
193
|
+
|
194
|
+
[Apollo documentation](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#inaccessible)
|
195
|
+
|
196
|
+
Call `inaccessible` within your class definition:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
class User < BaseObject
|
200
|
+
inaccessible
|
201
|
+
end
|
202
|
+
```
|
203
|
+
|
204
|
+
Pass the `inaccessible: true` option to your field definition:
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
class User < BaseObject
|
208
|
+
field :id, ID, null: false, inaccessible: true
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
### The `@override` directive (Apollo Federation v2)
|
213
|
+
|
214
|
+
[Apollo documentation](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#override)
|
215
|
+
|
216
|
+
Pass the `override:` option to your field definition:
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
class Product < BaseObject
|
220
|
+
field :id, ID, null: false
|
221
|
+
field :inStock, Boolean, null: false, override: { from: 'Products' }
|
222
|
+
end
|
223
|
+
```
|
224
|
+
|
163
225
|
### Field set syntax
|
164
226
|
|
165
227
|
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:
|
@@ -55,14 +55,14 @@ module ApolloFederation
|
|
55
55
|
|
56
56
|
def merge_directives(node, type)
|
57
57
|
if type.is_a?(ApolloFederation::HasDirectives)
|
58
|
-
directives = type.federation_directives
|
58
|
+
directives = type.federation_directives || []
|
59
59
|
else
|
60
60
|
directives = []
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
directives.each do |directive|
|
64
64
|
node = node.merge_directive(
|
65
|
-
name: directive[:name],
|
65
|
+
name: schema.federation_2? ? "federation__#{directive[:name]}" : directive[:name],
|
66
66
|
arguments: build_arguments_node(directive[:arguments]),
|
67
67
|
)
|
68
68
|
end
|
@@ -7,10 +7,29 @@ module ApolloFederation
|
|
7
7
|
module Field
|
8
8
|
include HasDirectives
|
9
9
|
|
10
|
-
|
10
|
+
VERSION_1_DIRECTIVES = %i[external requires provides].freeze
|
11
|
+
VERSION_2_DIRECTIVES = %i[shareable inaccessible override].freeze
|
12
|
+
|
13
|
+
def initialize(*args, **kwargs, &block)
|
14
|
+
add_v1_directives(**kwargs)
|
15
|
+
add_v2_directives(**kwargs)
|
16
|
+
|
17
|
+
# Remove the custom kwargs
|
18
|
+
kwargs = kwargs.delete_if do |k, _|
|
19
|
+
VERSION_1_DIRECTIVES.include?(k) || VERSION_2_DIRECTIVES.include?(k)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Pass on the default args:
|
23
|
+
super(*args, **kwargs, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def add_v1_directives(external: nil, requires: nil, provides: nil, **_kwargs)
|
11
29
|
if external
|
12
30
|
add_directive(name: 'external')
|
13
31
|
end
|
32
|
+
|
14
33
|
if requires
|
15
34
|
add_directive(
|
16
35
|
name: 'requires',
|
@@ -23,6 +42,7 @@ module ApolloFederation
|
|
23
42
|
],
|
24
43
|
)
|
25
44
|
end
|
45
|
+
|
26
46
|
if provides
|
27
47
|
add_directive(
|
28
48
|
name: 'provides',
|
@@ -36,8 +56,29 @@ module ApolloFederation
|
|
36
56
|
)
|
37
57
|
end
|
38
58
|
|
39
|
-
|
40
|
-
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_v2_directives(shareable: nil, inaccessible: nil, override: nil, **_kwargs)
|
63
|
+
if shareable
|
64
|
+
add_directive(name: 'shareable')
|
65
|
+
end
|
66
|
+
|
67
|
+
if inaccessible
|
68
|
+
add_directive(name: 'inaccessible')
|
69
|
+
end
|
70
|
+
|
71
|
+
if override
|
72
|
+
add_directive(
|
73
|
+
name: 'override',
|
74
|
+
arguments: [
|
75
|
+
name: 'from',
|
76
|
+
values: override[:from],
|
77
|
+
],
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
nil
|
41
82
|
end
|
42
83
|
end
|
43
84
|
end
|
@@ -16,6 +16,14 @@ module ApolloFederation
|
|
16
16
|
add_directive(name: 'extends')
|
17
17
|
end
|
18
18
|
|
19
|
+
def shareable
|
20
|
+
add_directive(name: 'shareable')
|
21
|
+
end
|
22
|
+
|
23
|
+
def inaccessible
|
24
|
+
add_directive(name: 'inaccessible')
|
25
|
+
end
|
26
|
+
|
19
27
|
def key(fields:, camelize: true)
|
20
28
|
add_directive(
|
21
29
|
name: 'key',
|
@@ -12,9 +12,30 @@ module ApolloFederation
|
|
12
12
|
end
|
13
13
|
|
14
14
|
module CommonMethods
|
15
|
+
FEDERATION_2_PREFIX = <<~SCHEMA
|
16
|
+
extend schema
|
17
|
+
@link(url: "https://specs.apollo.dev/federation/v2.0")
|
18
|
+
|
19
|
+
SCHEMA
|
20
|
+
|
21
|
+
def federation(version: '1.0')
|
22
|
+
@federation_version = version
|
23
|
+
end
|
24
|
+
|
25
|
+
def federation_version
|
26
|
+
@federation_version || '1.0'
|
27
|
+
end
|
28
|
+
|
29
|
+
def federation_2?
|
30
|
+
Gem::Version.new(federation_version.to_s) >= Gem::Version.new('2.0.0')
|
31
|
+
end
|
32
|
+
|
15
33
|
def federation_sdl(context: nil)
|
16
34
|
document_from_schema = FederatedDocumentFromSchemaDefinition.new(self, context: context)
|
17
|
-
|
35
|
+
|
36
|
+
output = GraphQL::Language::Printer.new.print(document_from_schema.document)
|
37
|
+
output.prepend(FEDERATION_2_PREFIX) if federation_2?
|
38
|
+
output
|
18
39
|
end
|
19
40
|
|
20
41
|
def query(new_query_object = nil)
|
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.
|
4
|
+
version: 3.1.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-
|
12
|
+
date: 2022-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: graphql
|