apollo-federation 1.1.3 → 1.1.4.beta.1

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: 8eef314d1457da9e7bd70ac5fe92c3d1168dfe340a3ba43a9d0e96475e44f027
4
- data.tar.gz: 675b88c92096f8d73e240b8c8ab8dc2a5429b0c5d3249c50c74f98f50839a9bf
3
+ metadata.gz: daf6d773f974fc148d5b0b512a26c9f93e0ab439326531a02bfed864d7fa6cb2
4
+ data.tar.gz: 3b1ff037218ae14fe2aee7557166bc1ab0fe9b91ba52f256d53e17bc63abea0e
5
5
  SHA512:
6
- metadata.gz: a5fb6b967baeeb09c89f60d52e7d25bff87966c20abb6f2577487316b3edd96afae6d400de968ecb92a3fd97ae0f06c057c1985e9f8d9a83fadc99392a0c8cc4
7
- data.tar.gz: 6b4574b0c718229d0b7ae717bddffdc1347d1d678e63ac3afdae54f58c1d4d5973ac76641c22129cb2ec5d661ce902f56bc43f06baf433739ac364303c816876
6
+ metadata.gz: '083988b5151aed2b559b1f3eeb7760df2ada9fddacba4385c3fed34b5087a6daf1913b73e77eb2c600e1eccb6a4d29e593071f3ccf2a834f6abf88cb7fe100cf'
7
+ data.tar.gz: c6af4542c73ccf7fffcc06e58a0a8c73b71439dd2a78565611e582cabfe48ca60799df011ebcfde75ab6c811142636dcb30b5486a0bfb3eea3f642f191d2e728
@@ -1,3 +1,10 @@
1
+ ## [1.1.4-beta.1](https://github.com/Gusto/apollo-federation-ruby/compare/v1.1.3...v1.1.4-beta.1) (2020-09-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **tracing:** properly handle parsing and validation errors ([#101](https://github.com/Gusto/apollo-federation-ruby/issues/101)) ([6cf8202](https://github.com/Gusto/apollo-federation-ruby/commit/6cf820281dd85bd358c6bf4c176b9a73a9280d54))
7
+
1
8
  ## [1.1.3](https://github.com/Gusto/apollo-federation-ruby/compare/v1.1.2...v1.1.3) (2020-07-16)
2
9
 
3
10
 
data/README.md CHANGED
@@ -175,14 +175,6 @@ To support [federated tracing](https://www.apollographql.com/docs/apollo-server/
175
175
  # ...
176
176
  end
177
177
  ```
178
- 3. Change your controller to attach the traces to the response:
179
- ```ruby
180
- def execute
181
- # ...
182
- result = YourSchema.execute(query, ...)
183
- render json: ApolloFederation::Tracing.attach_trace_to_result(result)
184
- end
185
- ```
186
178
 
187
179
  ## Known Issues and Limitations
188
180
  - Only works with class-based schemas, the legacy `.define` API will not be supported
@@ -4,14 +4,6 @@ module ApolloFederation
4
4
  module Tracing
5
5
  KEY = :ftv1
6
6
  DEBUG_KEY = "#{KEY}_debug".to_sym
7
- class NotInstalledError < StandardError
8
- MESSAGE = 'Apollo Federation Tracing not installed. \
9
- Add `use ApolloFederation::Tracing` to your schema.'
10
-
11
- def message
12
- MESSAGE
13
- end
14
- end
15
7
 
16
8
  module_function
17
9
 
@@ -23,37 +15,10 @@ Add `use ApolloFederation::Tracing` to your schema.'
23
15
  headers && headers['apollo-federation-include-trace'] == KEY.to_s
24
16
  end
25
17
 
26
- def attach_trace_to_result(result)
27
- return result unless result.context[:tracing_enabled]
28
-
29
- trace = result.context.namespace(KEY)
30
- # TODO: If there are errors during query validation, that could also cause a missing
31
- # start_time
32
- raise NotInstalledError unless trace[:start_time]
33
-
34
- result['errors']&.each do |error|
35
- trace[:node_map].add_error(error)
36
- end
37
-
38
- proto = ApolloFederation::Tracing::Trace.new(
39
- start_time: to_proto_timestamp(trace[:start_time]),
40
- end_time: to_proto_timestamp(trace[:end_time]),
41
- duration_ns: trace[:end_time_nanos] - trace[:start_time_nanos],
42
- root: trace[:node_map].root,
43
- )
44
-
45
- result[:extensions] ||= {}
46
- result[:extensions][KEY] = Base64.encode64(proto.class.encode(proto))
47
-
48
- if result.context[:debug_tracing]
49
- result[:extensions][DEBUG_KEY] = proto.to_h
50
- end
51
-
52
- result.to_h
53
- end
54
-
55
- def to_proto_timestamp(time)
56
- Google::Protobuf::Timestamp.new(seconds: time.to_i, nanos: time.nsec)
18
+ # @deprecated There is no need to call this method. Traces are added to the result automatically
19
+ def attach_trace_to_result(_result)
20
+ warn '[DEPRECATION] `attach_trace_to_result` is deprecated. There is no need to call it, as '\
21
+ 'traces are added to the result automatically'
57
22
  end
58
23
  end
59
24
  end
@@ -35,15 +35,15 @@ module ApolloFederation
35
35
  module Tracing
36
36
  module Tracer
37
37
  # store string constants to avoid creating new strings for each call to .trace
38
- EXECUTE_QUERY = 'execute_query'
38
+ EXECUTE_MULTIPLEX = 'execute_multiplex'
39
39
  EXECUTE_QUERY_LAZY = 'execute_query_lazy'
40
40
  EXECUTE_FIELD = 'execute_field'
41
41
  EXECUTE_FIELD_LAZY = 'execute_field_lazy'
42
42
 
43
43
  def self.trace(key, data, &block)
44
44
  case key
45
- when EXECUTE_QUERY
46
- execute_query(data, &block)
45
+ when EXECUTE_MULTIPLEX
46
+ execute_multiplex(data, &block)
47
47
  when EXECUTE_QUERY_LAZY
48
48
  execute_query_lazy(data, &block)
49
49
  when EXECUTE_FIELD
@@ -55,19 +55,26 @@ module ApolloFederation
55
55
  end
56
56
  end
57
57
 
58
- # Step 1:
59
- # Create a trace hash on the query context and record start times.
60
- def self.execute_query(data, &block)
61
- query = data.fetch(:query)
62
- return block.call unless query.context && query.context[:tracing_enabled]
58
+ def self.execute_multiplex(data, &block)
59
+ # Step 1:
60
+ # Create a trace hash on each query's context and record start times.
61
+ data.fetch(:multiplex).queries.each { |query| start_trace(query) }
62
+
63
+ results = block.call
64
+
65
+ # Step 5
66
+ # Attach the trace to the 'extensions' key of each result
67
+ results.map { |result| attach_trace_to_result(result) }
68
+ end
69
+
70
+ def self.start_trace(query)
71
+ return unless query.context && query.context[:tracing_enabled]
63
72
 
64
73
  query.context.namespace(ApolloFederation::Tracing::KEY).merge!(
65
74
  start_time: Time.now.utc,
66
75
  start_time_nanos: Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond),
67
76
  node_map: NodeMap.new,
68
77
  )
69
-
70
- block.call
71
78
  end
72
79
 
73
80
  # Step 4:
@@ -188,6 +195,37 @@ module ApolloFederation
188
195
  result
189
196
  end
190
197
  # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
198
+
199
+ def self.attach_trace_to_result(result)
200
+ return result unless result.context[:tracing_enabled]
201
+
202
+ trace = result.context.namespace(ApolloFederation::Tracing::KEY)
203
+
204
+ result['errors']&.each do |error|
205
+ trace[:node_map].add_error(error)
206
+ end
207
+
208
+ proto = ApolloFederation::Tracing::Trace.new(
209
+ start_time: to_proto_timestamp(trace[:start_time]),
210
+ end_time: to_proto_timestamp(trace[:end_time]),
211
+ duration_ns: trace[:end_time_nanos] - trace[:start_time_nanos],
212
+ root: trace[:node_map].root,
213
+ )
214
+
215
+ result[:extensions] ||= {}
216
+ result[:extensions][ApolloFederation::Tracing::KEY] =
217
+ Base64.encode64(proto.class.encode(proto))
218
+
219
+ if result.context[:debug_tracing]
220
+ result[:extensions][ApolloFederation::Tracing::DEBUG_KEY] = proto.to_h
221
+ end
222
+
223
+ result
224
+ end
225
+
226
+ def self.to_proto_timestamp(time)
227
+ Google::Protobuf::Timestamp.new(seconds: time.to_i, nanos: time.nsec)
228
+ end
191
229
  end
192
230
  end
193
231
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApolloFederation
4
- VERSION = '1.1.3'
4
+ VERSION = '1.1.4.beta.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: 1.1.3
4
+ version: 1.1.4.beta.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: 2020-07-16 00:00:00.000000000 Z
12
+ date: 2020-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql
@@ -191,8 +191,6 @@ files:
191
191
  - LICENSE
192
192
  - README.md
193
193
  - bin/generate-protos.sh
194
- - bin/prepare.rb
195
- - bin/publish.rb
196
194
  - bin/rspec
197
195
  - lib/apollo-federation.rb
198
196
  - lib/apollo-federation/any.rb
@@ -232,9 +230,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
232
230
  version: 2.2.0
233
231
  required_rubygems_version: !ruby/object:Gem::Requirement
234
232
  requirements:
235
- - - ">="
233
+ - - ">"
236
234
  - !ruby/object:Gem::Version
237
- version: '0'
235
+ version: 1.3.1
238
236
  requirements: []
239
237
  rubygems_version: 3.0.3
240
238
  signing_key:
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- def set_version
4
- new_version = ARGV[0]
5
-
6
- contents = File.read('lib/apollo-federation/version.rb')
7
-
8
- new_contents = contents.gsub(/VERSION = '[0-9.]*'/, "VERSION = '#{new_version}'")
9
- File.write('lib/apollo-federation/version.rb', new_contents)
10
- end
11
-
12
- def bundle_install
13
- system('bundle exec appraisal install')
14
- end
15
-
16
- def build_gem
17
- system('gem build apollo-federation.gemspec')
18
- end
19
-
20
- set_version
21
- bundle_install
22
- build_gem
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- new_version = ARGV[0]
4
- gem_name = "apollo-federation-#{new_version}.gem"
5
- system("gem push #{gem_name}")
6
- File.delete(gem_name)