apollo-federation 3.4.1 → 3.5.0

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: 7cffb53f08806faf67b0cb6859070ba9713e2a4041853ca085ed60e53544881a
4
- data.tar.gz: 49d268d70116760b61aa7c7edb9ed6cccf62fa15ae690a85e938714d39bd5ded
3
+ metadata.gz: 93e41c85366169cb54514dc0803b1a92c26ad684520ba328ff108ab67d20474c
4
+ data.tar.gz: 53b7ef86f0cf1e65849aed13cd4bfd625647eba6607efa08f2a566d450e5afd2
5
5
  SHA512:
6
- metadata.gz: f049907664be9ecb42f482af571799171e8d6156439fc816e3384bfbdae42709a289d1b25c7b6c42ad6a07afc7d3754b55b98eb2f03c9c72932e0f63a72f12c6
7
- data.tar.gz: 98e8fdb620d9f5007f2c690203372a3fb89dc5325aecdfd91f8287a160cf12d3793f24cf5c3f38b7fb80757fe2995e2d3135d7510ac9ab354faf4ffea24b2990
6
+ metadata.gz: 24e88953a0bbdc57273f82d05def242266e7368acd8962fb2648ef954c4379fc431b680fba853ee0ddca668fc8f39400e609d3fca8e9bf9248ed8dbf7e2971dd
7
+ data.tar.gz: ffd6c899084c8d26d30602ab34e80bfe343c2c6f847daa339130ab4272ccd04aa028b24e41725e1d1acbb00d132f9b81d9129ee8a9a79f0351e037dcb1a9ffc6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [3.5.0](https://github.com/Gusto/apollo-federation-ruby/compare/v3.4.1...v3.5.0) (2023-03-08)
2
+
3
+
4
+ ### Features
5
+
6
+ * add tag directive from federation v2 ([#210](https://github.com/Gusto/apollo-federation-ruby/issues/210)) ([8c6e112](https://github.com/Gusto/apollo-federation-ruby/commit/8c6e11251b7bc7d6888a7a2b6e0feeea70171cb0))
7
+
1
8
  ## [3.4.1](https://github.com/Gusto/apollo-federation-ruby/compare/v3.4.0...v3.4.1) (2023-02-21)
2
9
 
3
10
 
data/README.md CHANGED
@@ -222,6 +222,26 @@ class Product < BaseObject
222
222
  end
223
223
  ```
224
224
 
225
+ ### The `@tag` directive (Apollo Federation v2)
226
+
227
+ [Apollo documentation](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#tag)
228
+
229
+ Call `tag` within your class definition:
230
+
231
+ ```ruby
232
+ class User < BaseObject
233
+ tag name: 'private'
234
+ end
235
+ ```
236
+
237
+ Pass the `tags:` option to your field definition:
238
+
239
+ ```ruby
240
+ class User < BaseObject
241
+ field :id, ID, null: false, tags: [{ name: 'private' }]
242
+ end
243
+ ```
244
+
225
245
  ### Field set syntax
226
246
 
227
247
  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:
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apollo-federation/has_directives'
4
+
5
+ module ApolloFederation
6
+ module Argument
7
+ include HasDirectives
8
+
9
+ VERSION_2_DIRECTIVES = %i[tags].freeze
10
+
11
+ def initialize(*args, **kwargs, &block)
12
+ add_v2_directives(**kwargs)
13
+
14
+ # Remove the custom kwargs
15
+ kwargs = kwargs.delete_if do |k, _|
16
+ VERSION_2_DIRECTIVES.include?(k)
17
+ end
18
+
19
+ # Pass on the default args:
20
+ super(*args, **kwargs, &block)
21
+ end
22
+
23
+ private
24
+
25
+ def add_v2_directives(tags: [], **_kwargs)
26
+ tags.each do |tag|
27
+ add_directive(
28
+ name: 'tag',
29
+ arguments: [
30
+ name: 'name',
31
+ values: tag[:name],
32
+ ],
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apollo-federation/has_directives'
4
+
5
+ module ApolloFederation
6
+ module Enum
7
+ def self.included(klass)
8
+ klass.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ include HasDirectives
13
+
14
+ def tag(name:)
15
+ add_directive(name: 'tag', arguments: [name: 'name', values: name])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apollo-federation/has_directives'
4
+
5
+ module ApolloFederation
6
+ module EnumValue
7
+ include HasDirectives
8
+
9
+ VERSION_2_DIRECTIVES = %i[tags].freeze
10
+
11
+ def initialize(*args, **kwargs, &block)
12
+ add_v2_directives(**kwargs)
13
+
14
+ # Remove the custom kwargs
15
+ kwargs = kwargs.delete_if do |k, _|
16
+ VERSION_2_DIRECTIVES.include?(k)
17
+ end
18
+
19
+ # Pass on the default args:
20
+ super(*args, **kwargs, &block)
21
+ end
22
+
23
+ private
24
+
25
+ def add_v2_directives(tags: [], **_kwargs)
26
+ tags.each do |tag|
27
+ add_directive(
28
+ name: 'tag',
29
+ arguments: [
30
+ name: 'name',
31
+ values: tag[:name],
32
+ ],
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
@@ -14,7 +14,6 @@ module ApolloFederation
14
14
  '_entities',
15
15
  '_service',
16
16
  ].freeze
17
- INACCESSIBLE_DIRECTIVE = 'inaccessible'
18
17
 
19
18
  def build_object_type_node(object_type)
20
19
  object_node = super
@@ -28,8 +27,38 @@ module ApolloFederation
28
27
  end
29
28
 
30
29
  def build_interface_type_node(interface_type)
31
- field_node = super
32
- merge_directives(field_node, interface_type)
30
+ interface_node = super
31
+ merge_directives(interface_node, interface_type)
32
+ end
33
+
34
+ def build_union_type_node(union_type)
35
+ union_node = super
36
+ merge_directives(union_node, union_type)
37
+ end
38
+
39
+ def build_enum_type_node(enum_type)
40
+ enum_node = super
41
+ merge_directives(enum_node, enum_type)
42
+ end
43
+
44
+ def build_enum_value_node(enum_value_type)
45
+ enum_value_node = super
46
+ merge_directives(enum_value_node, enum_value_type)
47
+ end
48
+
49
+ def build_scalar_type_node(scalar_type)
50
+ scalar_node = super
51
+ merge_directives(scalar_node, scalar_type)
52
+ end
53
+
54
+ def build_input_object_node(input_object_type)
55
+ input_object_node = super
56
+ merge_directives(input_object_node, input_object_type)
57
+ end
58
+
59
+ def build_argument_node(argument_type)
60
+ argument_node = super
61
+ merge_directives(argument_node, argument_type)
33
62
  end
34
63
 
35
64
  def build_field_node(field_type)
@@ -71,7 +100,7 @@ module ApolloFederation
71
100
  end
72
101
 
73
102
  def directive_name(directive)
74
- if schema.federation_2? && directive[:name] != INACCESSIBLE_DIRECTIVE
103
+ if schema.federation_2? && !Schema::IMPORTED_DIRECTIVES.include?(directive[:name])
75
104
  "#{schema.link_namespace}__#{directive[:name]}"
76
105
  else
77
106
  directive[:name]
@@ -8,7 +8,7 @@ module ApolloFederation
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
11
+ VERSION_2_DIRECTIVES = %i[shareable inaccessible override tags].freeze
12
12
 
13
13
  def initialize(*args, **kwargs, &block)
14
14
  add_v1_directives(**kwargs)
@@ -59,7 +59,7 @@ module ApolloFederation
59
59
  nil
60
60
  end
61
61
 
62
- def add_v2_directives(shareable: nil, inaccessible: nil, override: nil, **_kwargs)
62
+ def add_v2_directives(shareable: nil, inaccessible: nil, override: nil, tags: [], **_kwargs)
63
63
  if shareable
64
64
  add_directive(name: 'shareable')
65
65
  end
@@ -78,6 +78,16 @@ module ApolloFederation
78
78
  )
79
79
  end
80
80
 
81
+ tags.each do |tag|
82
+ add_directive(
83
+ name: 'tag',
84
+ arguments: [
85
+ name: 'name',
86
+ values: tag[:name],
87
+ ],
88
+ )
89
+ end
90
+
81
91
  nil
82
92
  end
83
93
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apollo-federation/has_directives'
4
+
5
+ module ApolloFederation
6
+ module InputObject
7
+ def self.included(klass)
8
+ klass.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ include HasDirectives
13
+
14
+ def tag(name:)
15
+ add_directive(name: 'tag', arguments: [name: 'name', values: name])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -22,6 +22,10 @@ module ApolloFederation
22
22
  add_directive(name: 'inaccessible')
23
23
  end
24
24
 
25
+ def tag(name:)
26
+ add_directive(name: 'tag', arguments: [name: 'name', values: name])
27
+ end
28
+
25
29
  def key(fields:, camelize: true)
26
30
  add_directive(
27
31
  name: 'key',
@@ -28,6 +28,10 @@ module ApolloFederation
28
28
  add_directive(name: 'interfaceObject')
29
29
  end
30
30
 
31
+ def tag(name:)
32
+ add_directive(name: 'tag', arguments: [name: 'name', values: name])
33
+ end
34
+
31
35
  def key(fields:, camelize: true)
32
36
  add_directive(
33
37
  name: 'key',
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apollo-federation/has_directives'
4
+
5
+ module ApolloFederation
6
+ module Scalar
7
+ def self.included(klass)
8
+ klass.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ include HasDirectives
13
+
14
+ def tag(name:)
15
+ add_directive(name: 'tag', arguments: [name: 'name', values: name])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -7,6 +7,8 @@ require 'apollo-federation/federated_document_from_schema_definition.rb'
7
7
 
8
8
  module ApolloFederation
9
9
  module Schema
10
+ IMPORTED_DIRECTIVES = ['inaccessible', 'tag'].freeze
11
+
10
12
  def self.included(klass)
11
13
  klass.extend(CommonMethods)
12
14
  end
@@ -61,7 +63,7 @@ module ApolloFederation
61
63
 
62
64
  <<~SCHEMA
63
65
  extend schema
64
- @link(url: "https://specs.apollo.dev/federation/v2.3"#{federation_namespace}, import: ["@inaccessible"])
66
+ @link(url: "https://specs.apollo.dev/federation/v2.3"#{federation_namespace}, import: [#{(IMPORTED_DIRECTIVES.map { |directive| "\"@#{directive}\"" }).join(', ')}])
65
67
 
66
68
  SCHEMA
67
69
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apollo-federation/has_directives'
4
+
5
+ module ApolloFederation
6
+ module Union
7
+ def self.included(klass)
8
+ klass.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ include HasDirectives
13
+
14
+ def tag(name:)
15
+ add_directive(name: 'tag', arguments: [name: 'name', values: name])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApolloFederation
4
- VERSION = '3.4.1'
4
+ VERSION = '3.5.0'
5
5
  end
@@ -4,7 +4,13 @@ require 'apollo-federation/version'
4
4
  require 'apollo-federation/schema'
5
5
  require 'apollo-federation/object'
6
6
  require 'apollo-federation/interface'
7
+ require 'apollo-federation/union'
8
+ require 'apollo-federation/enum'
9
+ require 'apollo-federation/enum_value'
7
10
  require 'apollo-federation/field'
11
+ require 'apollo-federation/scalar'
12
+ require 'apollo-federation/input_object'
13
+ require 'apollo-federation/argument'
8
14
  require 'apollo-federation/tracing/proto'
9
15
  require 'apollo-federation/tracing/node_map'
10
16
  require 'apollo-federation/tracing/tracer'
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.1
4
+ version: 3.5.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-02-21 00:00:00.000000000 Z
12
+ date: 2023-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql
@@ -194,14 +194,19 @@ files:
194
194
  - bin/rspec
195
195
  - lib/apollo-federation.rb
196
196
  - lib/apollo-federation/any.rb
197
+ - lib/apollo-federation/argument.rb
197
198
  - lib/apollo-federation/entities_field.rb
198
199
  - lib/apollo-federation/entity.rb
200
+ - lib/apollo-federation/enum.rb
201
+ - lib/apollo-federation/enum_value.rb
199
202
  - lib/apollo-federation/federated_document_from_schema_definition.rb
200
203
  - lib/apollo-federation/field.rb
201
204
  - lib/apollo-federation/field_set_serializer.rb
202
205
  - lib/apollo-federation/has_directives.rb
206
+ - lib/apollo-federation/input_object.rb
203
207
  - lib/apollo-federation/interface.rb
204
208
  - lib/apollo-federation/object.rb
209
+ - lib/apollo-federation/scalar.rb
205
210
  - lib/apollo-federation/schema.rb
206
211
  - lib/apollo-federation/service.rb
207
212
  - lib/apollo-federation/service_field.rb
@@ -211,6 +216,7 @@ files:
211
216
  - lib/apollo-federation/tracing/proto/apollo.proto
212
217
  - lib/apollo-federation/tracing/proto/apollo_pb.rb
213
218
  - lib/apollo-federation/tracing/tracer.rb
219
+ - lib/apollo-federation/union.rb
214
220
  - lib/apollo-federation/version.rb
215
221
  homepage: https://github.com/Gusto/apollo-federation-ruby
216
222
  licenses: