graphql 2.2.7 → 2.2.9

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.

Potentially problematic release.


This version of graphql might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a49947bd83b909728424ef018fe58f3e4d7a2d1d1e0fd6688fc48fdf12026aae
4
- data.tar.gz: c369b4e0efaa1889cebd8774103e541e2860db4f920962bcc107cdbf3c072ca2
3
+ metadata.gz: 1a6fd973959b00f0c33ea17df3e1a5b8a11f51b426c987ea9f202e925c721e14
4
+ data.tar.gz: 89191c20a40c0084375f2f711d12989e349982c5f27a27390889dc291f016e4e
5
5
  SHA512:
6
- metadata.gz: '059d1323a0bfe78d29bfdcf2523b26cf3d3a82195d1b8f4a490092a61ce074ae232c7e93e6330b9659d07d28b7cd66a0f2d42e0f38040556ec265773d4a34260'
7
- data.tar.gz: 6bd1e3ddc66378e37914fb54806560ca05aeb1294bea4704f53b6445f3b83883ccab45c2d2b0c6b750fd37f4b10aa1351065bb0553f13429ede9343174e1dc62
6
+ metadata.gz: 6e862a85cf5f43693401461886d4f984703a6b221dc56c175f42a82fa81f0d9c77b7793247edab69eb85a2aa9930b7ba45ec3412a6642e263dc0e03ea5f58fe7
7
+ data.tar.gz: 81d6a4de1214ed84ac55cf37ce76825de67e62a0728a950f5c20dbf3faa8e61420099dcfcc1841ea09f69f94b8a1c36e60a90799a33df64e2dd676a13b4cd1dd
@@ -111,15 +111,15 @@ module GraphQL
111
111
  data_result
112
112
  end
113
113
  else
114
- result = {
115
- "data" => query.context.namespace(:interpreter_runtime)[:runtime].final_result
116
- }
114
+ result = {}
117
115
 
118
116
  if query.context.errors.any?
119
117
  error_result = query.context.errors.map(&:to_h)
120
118
  result["errors"] = error_result
121
119
  end
122
120
 
121
+ result["data"] = query.context.namespace(:interpreter_runtime)[:runtime].final_result
122
+
123
123
  result
124
124
  end
125
125
  if query.context.namespace?(:__query_result_extensions__)
@@ -1,18 +1,16 @@
1
1
  # frozen_string_literal: true
2
-
3
- require 'graphql/schema/base_64_bp'
4
-
2
+ require "base64"
5
3
  module GraphQL
6
4
  class Schema
7
5
  # @api private
8
6
  module Base64Encoder
9
7
  def self.encode(unencoded_text, nonce: false)
10
- Base64Bp.urlsafe_encode64(unencoded_text, padding: false)
8
+ Base64.urlsafe_encode64(unencoded_text, padding: false)
11
9
  end
12
10
 
13
11
  def self.decode(encoded_text, nonce: false)
14
12
  # urlsafe_decode64 is for forward compatibility
15
- Base64Bp.urlsafe_decode64(encoded_text)
13
+ Base64.urlsafe_decode64(encoded_text)
16
14
  rescue ArgumentError
17
15
  raise GraphQL::ExecutionError, "Invalid input: #{encoded_text.inspect}"
18
16
  end
@@ -483,41 +483,24 @@ module GraphQL
483
483
  metadata_complexity = 0
484
484
  lookahead = GraphQL::Execution::Lookahead.new(query: query, field: self, ast_nodes: nodes, owner_type: owner)
485
485
 
486
- if (page_info_lookahead = lookahead.selection(:page_info)).selected?
487
- metadata_complexity += 1 # pageInfo
488
- metadata_complexity += page_info_lookahead.selections.size # subfields
489
- end
490
-
491
- if lookahead.selects?(:total) || lookahead.selects?(:total_count) || lookahead.selects?(:count)
492
- metadata_complexity += 1
486
+ lookahead.selections.each do |next_lookahead|
487
+ # this includes `pageInfo`, `nodes` and `edges` and any custom fields
488
+ # TODO this doesn't support procs yet -- unlikely to need it.
489
+ metadata_complexity += next_lookahead.field.complexity
490
+ if next_lookahead.name != :nodes && next_lookahead.name != :edges
491
+ # subfields, eg, for pageInfo -- assumes no subselections
492
+ metadata_complexity += next_lookahead.selections.size
493
+ end
493
494
  end
494
495
 
495
- nodes_edges_complexity = 0
496
- nodes_edges_complexity += 1 if lookahead.selects?(:edges)
497
- nodes_edges_complexity += 1 if lookahead.selects?(:nodes)
498
-
499
496
  # Possible bug: selections on `edges` and `nodes` are _both_ multiplied here. Should they be?
500
- items_complexity = child_complexity - metadata_complexity - nodes_edges_complexity
501
- # Add 1 for _this_ field
502
- 1 + (max_possible_page_size * items_complexity) + metadata_complexity + nodes_edges_complexity
497
+ items_complexity = child_complexity - metadata_complexity
498
+ subfields_complexity = (max_possible_page_size * items_complexity) + metadata_complexity
499
+ # Apply this field's own complexity
500
+ apply_own_complexity_to(subfields_complexity, query, nodes)
503
501
  end
504
502
  else
505
- defined_complexity = complexity
506
- case defined_complexity
507
- when Proc
508
- arguments = query.arguments_for(nodes.first, self)
509
- if arguments.is_a?(GraphQL::ExecutionError)
510
- return child_complexity
511
- elsif arguments.respond_to?(:keyword_arguments)
512
- arguments = arguments.keyword_arguments
513
- end
514
-
515
- defined_complexity.call(query.context, arguments, child_complexity)
516
- when Numeric
517
- defined_complexity + child_complexity
518
- else
519
- raise("Invalid complexity: #{defined_complexity.inspect} on #{path} (#{inspect})")
520
- end
503
+ apply_own_complexity_to(child_complexity, query, nodes)
521
504
  end
522
505
  end
523
506
 
@@ -882,6 +865,24 @@ ERR
882
865
  yield(obj, args)
883
866
  end
884
867
  end
868
+
869
+ def apply_own_complexity_to(child_complexity, query, nodes)
870
+ case (own_complexity = complexity)
871
+ when Numeric
872
+ own_complexity + child_complexity
873
+ when Proc
874
+ arguments = query.arguments_for(nodes.first, self)
875
+ if arguments.is_a?(GraphQL::ExecutionError)
876
+ return child_complexity
877
+ elsif arguments.respond_to?(:keyword_arguments)
878
+ arguments = arguments.keyword_arguments
879
+ end
880
+
881
+ own_complexity.call(query.context, arguments, child_complexity)
882
+ else
883
+ raise ArgumentError, "Invalid complexity for #{self.path}: #{own_complexity.inspect}"
884
+ end
885
+ end
885
886
  end
886
887
  end
887
888
  end
@@ -166,11 +166,15 @@ module GraphQL
166
166
  args.each_value do |argument|
167
167
  arg_keyword = argument.keyword
168
168
  if inputs.key?(arg_keyword) && !(arg_value = inputs[arg_keyword]).nil? && (arg_value != argument.default_value)
169
- arg_auth, err = argument.authorized?(self, arg_value, context)
170
- if !arg_auth
171
- return arg_auth, err
172
- else
173
- true
169
+ auth_result = argument.authorized?(self, arg_value, context)
170
+ if auth_result.is_a?(Array)
171
+ # only return this second value if the application returned a second value
172
+ arg_auth, err = auth_result
173
+ if !arg_auth
174
+ return arg_auth, err
175
+ end
176
+ elsif auth_result == false
177
+ return auth_result
174
178
  end
175
179
  else
176
180
  true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'graphql/schema/base_64_bp'
2
+ require "base64"
3
3
 
4
4
  module GraphQL
5
5
  class Schema
@@ -148,6 +148,8 @@ module GraphQL
148
148
  { TIMESTAMP_KEY => [obj.class.name, obj.strftime(TIMESTAMP_FORMAT)] }
149
149
  elsif obj.is_a?(OpenStruct)
150
150
  { OPEN_STRUCT_KEY => dump_value(obj.to_h) }
151
+ elsif defined?(ActiveRecord::Relation) && obj.is_a?(ActiveRecord::Relation)
152
+ dump_value(obj.to_a)
151
153
  else
152
154
  obj
153
155
  end
@@ -5,10 +5,7 @@ module GraphQL
5
5
  # @param schema_class [Class<GraphQL::Schema>]
6
6
  # @return [Module] A helpers module which always uses the given schema
7
7
  def self.for(schema_class)
8
- Module.new do
9
- include SchemaHelpers
10
- @@schema_class_for_helpers = schema_class
11
- end
8
+ SchemaHelpers.for(schema_class)
12
9
  end
13
10
 
14
11
  class Error < GraphQL::Error
@@ -119,6 +116,13 @@ module GraphQL
119
116
  # schema will be added later
120
117
  super(nil, *args, **kwargs, &block)
121
118
  end
119
+
120
+ def self.for(schema_class)
121
+ Module.new do
122
+ include SchemaHelpers
123
+ @@schema_class_for_helpers = schema_class
124
+ end
125
+ end
122
126
  end
123
127
  end
124
128
  end
@@ -16,8 +16,8 @@ module GraphQL
16
16
  "execute_query_lazy" => "graphql.execute"
17
17
  }.each do |trace_method, platform_key|
18
18
  module_eval <<-RUBY, __FILE__, __LINE__
19
- def #{trace_method}(**data, &block)
20
- instrument_execution("#{platform_key}", "#{trace_method}", data, &block)
19
+ def #{trace_method}(**data)
20
+ instrument_execution("#{platform_key}", "#{trace_method}", data) { super }
21
21
  end
22
22
  RUBY
23
23
  end
@@ -64,9 +64,10 @@ module GraphQL
64
64
  return yield unless Sentry.initialized?
65
65
 
66
66
  Sentry.with_child_span(op: platform_key, start_timestamp: Sentry.utc_now.to_f) do |span|
67
- result = block.call
68
- span.finish
67
+ result = yield
68
+ return result unless span
69
69
 
70
+ span.finish
70
71
  if trace_method == "execute_multiplex" && data.key?(:multiplex)
71
72
  operation_names = data[:multiplex].queries.map{|q| operation_name(q) }
72
73
  span.set_description(operation_names.join(", "))
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "2.2.7"
3
+ VERSION = "2.2.9"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.7
4
+ version: 2.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-29 00:00:00.000000000 Z
11
+ date: 2024-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -386,7 +386,6 @@ files:
386
386
  - lib/graphql/schema/addition.rb
387
387
  - lib/graphql/schema/always_visible.rb
388
388
  - lib/graphql/schema/argument.rb
389
- - lib/graphql/schema/base_64_bp.rb
390
389
  - lib/graphql/schema/base_64_encoder.rb
391
390
  - lib/graphql/schema/build_from_definition.rb
392
391
  - lib/graphql/schema/build_from_definition/resolve_map.rb
@@ -602,6 +601,7 @@ metadata:
602
601
  source_code_uri: https://github.com/rmosolgo/graphql-ruby
603
602
  bug_tracker_uri: https://github.com/rmosolgo/graphql-ruby/issues
604
603
  mailing_list_uri: https://buttondown.email/graphql-ruby
604
+ rubygems_mfa_required: 'true'
605
605
  post_install_message:
606
606
  rdoc_options: []
607
607
  require_paths:
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'base64'
4
-
5
- # backport from ruby v2.5 to v2.2 that has no `padding` things
6
- # @api private
7
- module Base64Bp
8
- extend Base64
9
-
10
- module_function
11
-
12
- def urlsafe_encode64(bin, padding:)
13
- str = strict_encode64(bin)
14
- str.tr!("+/", "-_")
15
- str.delete!("=") unless padding
16
- str
17
- end
18
-
19
- def urlsafe_decode64(str)
20
- str = str.tr("-_", "+/")
21
- if !str.end_with?("=") && str.length % 4 != 0
22
- str = str.ljust((str.length + 3) & ~3, "=")
23
- end
24
- strict_decode64(str)
25
- end
26
- end