graphql 2.1.6 → 2.1.7

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: 9016cf336ff2bee9f58e074f1402347676f93f9fe3310a7ae13db84fb94b4c40
4
- data.tar.gz: 0e9dd85e27ffe62fbb8c8acbd749c00e4c45aa9e90440975e00a8682f43014bf
3
+ metadata.gz: f0e3e74b44a52e45b992da7fe79d28ff53ea9871ac621517888f887c1a0bd8fb
4
+ data.tar.gz: fc0a67822082dfc133b1b7f44135df17a5181de2e8404d4b756c4ac0b69a9761
5
5
  SHA512:
6
- metadata.gz: fa610bc9bad0daae1e7e951c35290cafdeccb17ae726d905a0eb2c44b0b7ae7887a42b3937fe556e16cc9469448164928d6690e64bd6e6e862768ca715682cca
7
- data.tar.gz: 9bb2b85296f05df54cf47a904d8a37d2723b6293db97ee08eab50fe70a02d99ebd7f97a5e6ab8638a59e0ff902055f9a87d3aa1ebd36d78fc6b4f34910df720d
6
+ metadata.gz: 00bcdc566706f6fc323b0872c5c36230e7964a518e37825dc14a49cc274cbcac099ab3dca8a24608fafb598dcdfb5c239abb2be81359fd234dbce6954530c044
7
+ data.tar.gz: efb58609553a215455f026bd686b01c699ea858a732733554198150c1c6a0b8f4b60b514c3aa0532bdc611267039c413cb82b5a63bff7a2a7f6b948a3c154814
@@ -2,6 +2,12 @@
2
2
  module GraphQL
3
3
  class Backtrace
4
4
  module Trace
5
+ def initialize(*args, **kwargs, &block)
6
+ @__backtrace_contexts = {}
7
+ @__backtrace_last_context = nil
8
+ super
9
+ end
10
+
5
11
  def validate(query:, validate:)
6
12
  if query.multiplex
7
13
  push_query_backtrace_context(query)
@@ -42,36 +48,27 @@ module GraphQL
42
48
  rescue StandardError => err
43
49
  # This is an unhandled error from execution,
44
50
  # Re-raise it with a GraphQL trace.
45
- multiplex_context = multiplex.context
46
- potential_context = multiplex_context[:last_graphql_backtrace_context]
47
-
51
+ potential_context = @__backtrace_last_context
48
52
  if potential_context.is_a?(GraphQL::Query::Context) ||
49
53
  potential_context.is_a?(Backtrace::Frame)
50
54
  raise TracedError.new(err, potential_context)
51
55
  else
52
56
  raise
53
57
  end
54
- ensure
55
- multiplex_context = multiplex.context
56
- multiplex_context.delete(:graphql_backtrace_contexts)
57
- multiplex_context.delete(:last_graphql_backtrace_context)
58
58
  end
59
59
 
60
60
  private
61
61
 
62
62
  def push_query_backtrace_context(query)
63
63
  push_data = query
64
- multiplex = query.multiplex
65
64
  push_key = []
66
- push_storage = multiplex.context[:graphql_backtrace_contexts] ||= {}
67
- push_storage[push_key] = push_data
68
- multiplex.context[:last_graphql_backtrace_context] = push_data
65
+ @__backtrace_contexts[push_key] = push_data
66
+ @__backtrace_last_context = push_data
69
67
  end
70
68
 
71
69
  def push_field_backtrace_context(field, query, ast_node, arguments, object)
72
- multiplex = query.multiplex
73
70
  push_key = query.context[:current_path]
74
- push_storage = multiplex.context[:graphql_backtrace_contexts]
71
+ push_storage = @__backtrace_contexts
75
72
  parent_frame = push_storage[push_key[0..-2]]
76
73
 
77
74
  if parent_frame.is_a?(GraphQL::Query)
@@ -87,10 +84,10 @@ module GraphQL
87
84
  arguments: arguments,
88
85
  parent_frame: parent_frame,
89
86
  )
90
-
91
87
  push_storage[push_key] = push_data
92
- multiplex.context[:last_graphql_backtrace_context] = push_data
88
+ @__backtrace_last_context = push_data
93
89
  end
90
+
94
91
  end
95
92
  end
96
93
  end
@@ -25,7 +25,7 @@ module GraphQL
25
25
  queries = query_options.map do |opts|
26
26
  case opts
27
27
  when Hash
28
- GraphQL::Query.new(schema, nil, **opts)
28
+ schema.query_class.new(schema, nil, **opts)
29
29
  when GraphQL::Query
30
30
  opts
31
31
  else
@@ -47,10 +47,10 @@ module GraphQL
47
47
  end
48
48
 
49
49
  # Remove leading & trailing blank lines
50
- while lines.size > 0 && lines[0].empty?
50
+ while lines.size > 0 && contains_only_whitespace?(lines.first)
51
51
  lines.shift
52
52
  end
53
- while lines.size > 0 && lines[-1].empty?
53
+ while lines.size > 0 && contains_only_whitespace?(lines.last)
54
54
  lines.pop
55
55
  end
56
56
 
@@ -106,6 +106,10 @@ module GraphQL
106
106
 
107
107
  nil
108
108
  end
109
+
110
+ def self.contains_only_whitespace?(line)
111
+ line.match?(/^\s*$/)
112
+ end
109
113
  end
110
114
  end
111
115
  end
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
+ require "graphql/query/context"
2
3
  module GraphQL
3
4
  class Query
4
5
  # This object can be `ctx` in places where there is no query
5
- class NullContext
6
+ class NullContext < Context
6
7
  include Singleton
7
8
 
8
9
  class NullQuery
data/lib/graphql/query.rb CHANGED
@@ -115,8 +115,6 @@ module GraphQL
115
115
  if schema.trace_class <= GraphQL::Tracing::CallLegacyTracers
116
116
  context_tracers += [GraphQL::Backtrace::Tracer]
117
117
  @tracers << GraphQL::Backtrace::Tracer
118
- elsif !(current_trace.class <= GraphQL::Backtrace::Trace)
119
- raise "Invariant: `backtrace: true` should have provided a trace class with Backtrace mixed in, but it didnt. (Found: #{current_trace.class.ancestors}). This is a bug in GraphQL-Ruby, please report it on GitHub."
120
118
  end
121
119
  end
122
120
 
@@ -145,7 +145,7 @@ module GraphQL
145
145
  end
146
146
 
147
147
  # @api private
148
- INVALID_OBJECT_MESSAGE = "Expected %{object} to be a key-value object responding to `to_h` or `to_unsafe_h`."
148
+ INVALID_OBJECT_MESSAGE = "Expected %{object} to be a key-value object."
149
149
 
150
150
  def validate_non_null_input(input, ctx, max_errors: nil)
151
151
  warden = ctx.warden
@@ -21,7 +21,7 @@ module GraphQL
21
21
  if @reauthorize_scoped_objects != nil
22
22
  @reauthorize_scoped_objects
23
23
  else
24
- find_inherited_value(:reauthorize_scoped_objects, nil)
24
+ find_inherited_value(:reauthorize_scoped_objects, true)
25
25
  end
26
26
  else
27
27
  @reauthorize_scoped_objects = new_value
@@ -680,7 +680,7 @@ module GraphQL
680
680
  else
681
681
  string_or_document
682
682
  end
683
- query = GraphQL::Query.new(self, document: doc, context: context)
683
+ query = query_class.new(self, document: doc, context: context)
684
684
  validator_opts = { schema: self }
685
685
  rules && (validator_opts[:rules] = rules)
686
686
  validator = GraphQL::StaticValidation::Validator.new(**validator_opts)
@@ -688,6 +688,14 @@ module GraphQL
688
688
  res[:errors]
689
689
  end
690
690
 
691
+ def query_class(new_query_class = NOT_CONFIGURED)
692
+ if NOT_CONFIGURED.equal?(new_query_class)
693
+ @query_class || (superclass.respond_to?(:query_class) ? superclass.query_class : GraphQL::Query)
694
+ else
695
+ @query_class = new_query_class
696
+ end
697
+ end
698
+
691
699
  attr_writer :validate_max_errors
692
700
 
693
701
  def validate_max_errors(new_validate_max_errors = nil)
@@ -126,7 +126,13 @@ module GraphQL
126
126
  when GraphQL::Schema::InputObject
127
127
  stringify_args(arg_owner, args.to_h, context)
128
128
  else
129
- args
129
+ if arg_owner.is_a?(Class) && arg_owner < GraphQL::Schema::Enum
130
+ # `prepare:` may have made the value something other than
131
+ # a defined value of this enum -- use _that_ in this case.
132
+ arg_owner.coerce_isolated_input(args) || args
133
+ else
134
+ args
135
+ end
130
136
  end
131
137
  end
132
138
 
@@ -62,7 +62,7 @@ module GraphQL
62
62
  # @return [void]
63
63
  def trigger(event_name, args, object, scope: nil, context: {})
64
64
  # Make something as context-like as possible, even though there isn't a current query:
65
- dummy_query = GraphQL::Query.new(@schema, "{ __typename }", validate: false, context: context)
65
+ dummy_query = @schema.query_class.new(@schema, "{ __typename }", validate: false, context: context)
66
66
  context = dummy_query.context
67
67
  event_name = event_name.to_s
68
68
 
@@ -234,7 +234,7 @@ module GraphQL
234
234
 
235
235
  # @return [Boolean] if true, then a query like this one would be broadcasted
236
236
  def broadcastable?(query_str, **query_options)
237
- query = GraphQL::Query.new(@schema, query_str, **query_options)
237
+ query = @schema.query_class.new(@schema, query_str, **query_options)
238
238
  if !query.valid?
239
239
  raise "Invalid query: #{query.validation_errors.map(&:to_h).inspect}"
240
240
  end
@@ -87,6 +87,19 @@ module GraphQL
87
87
  node_type.scope_items(items, context)
88
88
  end
89
89
 
90
+ # The connection will skip auth on its nodes if the node_type is configured for that
91
+ def reauthorize_scoped_objects(new_value = nil)
92
+ if new_value.nil?
93
+ if @reauthorize_scoped_objects != nil
94
+ @reauthorize_scoped_objects
95
+ else
96
+ node_type.reauthorize_scoped_objects
97
+ end
98
+ else
99
+ @reauthorize_scoped_objects = new_value
100
+ end
101
+ end
102
+
90
103
  # Add the shortcut `nodes` field to this connection and its subclasses
91
104
  def nodes_field(node_nullable: self.node_nullable, field_options: nil)
92
105
  define_nodes_field(node_nullable, field_options: field_options)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "2.1.6"
3
+ VERSION = "2.1.7"
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.1.6
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-02 00:00:00.000000000 Z
11
+ date: 2023-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: racc