graphql 2.0.18 → 2.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -72,18 +72,6 @@ module GraphQL
72
72
  # @return [Array<String, Integer>] The current position in the result
73
73
  attr_reader :path
74
74
 
75
- module EmptyScopedContext
76
- EMPTY_HASH = {}.freeze
77
-
78
- def self.key?(k)
79
- false
80
- end
81
-
82
- def self.merged_context
83
- EMPTY_HASH
84
- end
85
- end
86
-
87
75
  # Make a new context which delegates key lookup to `values`
88
76
  # @param query [GraphQL::Query] the query who owns this context
89
77
  # @param values [Hash] A hash of arbitrary values which will be accessible at query-time
@@ -99,28 +87,35 @@ module GraphQL
99
87
  @path = []
100
88
  @value = nil
101
89
  @context = self # for SharedMethods TODO delete sharedmethods
102
- @scoped_context = EmptyScopedContext
90
+ @scoped_context = ScopedContext.new(self)
103
91
  end
104
92
 
105
93
  class ScopedContext
94
+ NO_PATH = [].freeze
95
+ NO_CONTEXT = {}.freeze
96
+
106
97
  def initialize(query_context)
107
98
  @query_context = query_context
108
- @scoped_contexts = {}
109
- @all_keys = Set.new
110
- @no_path = [].freeze
99
+ @scoped_contexts = nil
100
+ @all_keys = nil
111
101
  end
112
102
 
113
103
  def merged_context
114
- merged_ctx = {}
115
- each_present_path_ctx do |path_ctx|
116
- merged_ctx = path_ctx.merge(merged_ctx)
104
+ if @scoped_contexts.nil?
105
+ NO_CONTEXT
106
+ else
107
+ merged_ctx = {}
108
+ each_present_path_ctx do |path_ctx|
109
+ merged_ctx = path_ctx.merge(merged_ctx)
110
+ end
111
+ merged_ctx
117
112
  end
118
- merged_ctx
119
113
  end
120
114
 
121
115
  def merge!(hash)
116
+ @all_keys ||= Set.new
122
117
  @all_keys.merge(hash.keys)
123
- ctx = @scoped_contexts
118
+ ctx = @scoped_contexts ||= {}
124
119
  current_path.each do |path_part|
125
120
  ctx = ctx[path_part] ||= { parent: ctx }
126
121
  end
@@ -129,7 +124,7 @@ module GraphQL
129
124
  end
130
125
 
131
126
  def key?(key)
132
- if @all_keys.include?(key)
127
+ if @all_keys && @all_keys.include?(key)
133
128
  each_present_path_ctx do |path_ctx|
134
129
  if path_ctx.key?(key)
135
130
  return true
@@ -149,7 +144,7 @@ module GraphQL
149
144
  end
150
145
 
151
146
  def current_path
152
- @query_context.current_path || @no_path
147
+ @query_context.current_path || NO_PATH
153
148
  end
154
149
 
155
150
  def dig(key, *other_keys)
@@ -172,19 +167,23 @@ module GraphQL
172
167
  # but look up the tree for previously-assigned scoped values
173
168
  def each_present_path_ctx
174
169
  ctx = @scoped_contexts
175
- current_path.each do |path_part|
176
- if ctx.key?(path_part)
177
- ctx = ctx[path_part]
178
- else
179
- break
170
+ if ctx.nil?
171
+ # no-op
172
+ else
173
+ current_path.each do |path_part|
174
+ if ctx.key?(path_part)
175
+ ctx = ctx[path_part]
176
+ else
177
+ break
178
+ end
180
179
  end
181
- end
182
180
 
183
- while ctx
184
- if (scoped_ctx = ctx[:scoped_context])
185
- yield(scoped_ctx)
181
+ while ctx
182
+ if (scoped_ctx = ctx[:scoped_context])
183
+ yield(scoped_ctx)
184
+ end
185
+ ctx = ctx[:parent]
186
186
  end
187
- ctx = ctx[:parent]
188
187
  end
189
188
  end
190
189
  end
@@ -329,9 +328,6 @@ module GraphQL
329
328
  end
330
329
 
331
330
  def scoped_merge!(hash)
332
- if @scoped_context == EmptyScopedContext
333
- @scoped_context = ScopedContext.new(self)
334
- end
335
331
  @scoped_context.merge!(hash)
336
332
  end
337
333
 
@@ -752,6 +752,8 @@ module GraphQL
752
752
  end
753
753
  # if the line above doesn't raise, re-raise
754
754
  raise
755
+ rescue GraphQL::ExecutionError => err
756
+ err
755
757
  end
756
758
 
757
759
  # @param ctx [GraphQL::Query::Context]
@@ -46,7 +46,7 @@ module GraphQL
46
46
  elsif defined?(@description)
47
47
  @description
48
48
  else
49
- nil
49
+ @description = nil
50
50
  end
51
51
  end
52
52
 
@@ -56,8 +56,12 @@ module GraphQL
56
56
  def inherited(child_class)
57
57
  child_class.introspection(introspection)
58
58
  child_class.description(description)
59
- if defined?(@graphql_name) && (self.name.nil? || graphql_name != default_graphql_name)
59
+ child_class.default_graphql_name = nil
60
+
61
+ if defined?(@graphql_name) && @graphql_name && (self.name.nil? || graphql_name != default_graphql_name)
60
62
  child_class.graphql_name(graphql_name)
63
+ else
64
+ child_class.graphql_name = nil
61
65
  end
62
66
  super
63
67
  end
@@ -98,7 +102,8 @@ module GraphQL
98
102
  def default_graphql_name
99
103
  @default_graphql_name ||= begin
100
104
  raise GraphQL::RequiredImplementationMissingError, 'Anonymous class should declare a `graphql_name`' if name.nil?
101
- -name.split("::").last.sub(/Type\Z/, "") end
105
+ -name.split("::").last.sub(/Type\Z/, "")
106
+ end
102
107
  end
103
108
 
104
109
  def visible?(context)
@@ -109,16 +114,13 @@ module GraphQL
109
114
  true
110
115
  end
111
116
 
112
- protected
113
-
114
- attr_writer :default_graphql_name
117
+ def default_relay
118
+ false
119
+ end
115
120
 
116
- private
121
+ protected
117
122
 
118
- def inherited(subclass)
119
- super
120
- subclass.default_graphql_name = nil
121
- end
123
+ attr_writer :default_graphql_name, :graphql_name
122
124
  end
123
125
  end
124
126
  end
@@ -3,6 +3,16 @@ module GraphQL
3
3
  class Schema
4
4
  class Member
5
5
  module HasAstNode
6
+ def self.extended(child_cls)
7
+ super
8
+ child_cls.ast_node = nil
9
+ end
10
+
11
+ def inherited(child_cls)
12
+ super
13
+ child_cls.ast_node = nil
14
+ end
15
+
6
16
  # If this schema was parsed from a `.graphql` file (or other SDL),
7
17
  # this is the AST node that defined this part of the schema.
8
18
  def ast_node(new_ast_node = nil)
@@ -14,6 +24,8 @@ module GraphQL
14
24
  nil
15
25
  end
16
26
  end
27
+
28
+ attr_writer :ast_node
17
29
  end
18
30
  end
19
31
  end
@@ -4,6 +4,16 @@ module GraphQL
4
4
  class Schema
5
5
  class Member
6
6
  module HasDirectives
7
+ def self.extended(child_cls)
8
+ super
9
+ child_cls.module_eval { self.own_directives = nil }
10
+ end
11
+
12
+ def inherited(child_cls)
13
+ super
14
+ child_cls.own_directives = nil
15
+ end
16
+
7
17
  # Create an instance of `dir_class` for `self`, using `options`.
8
18
  #
9
19
  # It removes a previously-attached instance of `dir_class`, if there is one.
@@ -101,12 +111,9 @@ module GraphQL
101
111
  end
102
112
  end
103
113
 
104
-
105
114
  protected
106
115
 
107
- def own_directives
108
- @own_directives
109
- end
116
+ attr_accessor :own_directives
110
117
  end
111
118
  end
112
119
  end
@@ -138,6 +138,7 @@ module GraphQL
138
138
  super
139
139
  subclass.class_eval do
140
140
  @own_fields ||= nil
141
+ @field_class ||= nil
141
142
  end
142
143
  end
143
144
 
@@ -6,6 +6,7 @@ module GraphQL
6
6
  module RelayShortcuts
7
7
  def edge_type_class(new_edge_type_class = nil)
8
8
  if new_edge_type_class
9
+ initialize_relay_metadata
9
10
  @edge_type_class = new_edge_type_class
10
11
  else
11
12
  # Don't call `ancestor.edge_type_class`
@@ -22,6 +23,7 @@ module GraphQL
22
23
 
23
24
  def connection_type_class(new_connection_type_class = nil)
24
25
  if new_connection_type_class
26
+ initialize_relay_metadata
25
27
  @connection_type_class = new_connection_type_class
26
28
  else
27
29
  # Don't call `ancestor.connection_type_class`
@@ -37,6 +39,7 @@ module GraphQL
37
39
  end
38
40
 
39
41
  def edge_type
42
+ initialize_relay_metadata
40
43
  @edge_type ||= begin
41
44
  edge_name = self.graphql_name + "Edge"
42
45
  node_type_class = self
@@ -48,6 +51,7 @@ module GraphQL
48
51
  end
49
52
 
50
53
  def connection_type
54
+ initialize_relay_metadata
51
55
  @connection_type ||= begin
52
56
  conn_name = self.graphql_name + "Connection"
53
57
  edge_type_class = self.edge_type
@@ -67,6 +71,21 @@ module GraphQL
67
71
  def configured_edge_type_class
68
72
  @edge_type_class
69
73
  end
74
+
75
+ attr_writer :edge_type, :connection_type, :connection_type_class, :edge_type_class
76
+
77
+ private
78
+
79
+ # If one of thse values is accessed, initialize all the instance variables to retain
80
+ # a consistent object shape.
81
+ def initialize_relay_metadata
82
+ if !defined?(@connection_type)
83
+ @connection_type = nil
84
+ @edge_type = nil
85
+ @connection_type_class = nil
86
+ @edge_type_class = nil
87
+ end
88
+ end
70
89
  end
71
90
  end
72
91
  end
@@ -43,11 +43,11 @@ module GraphQL
43
43
  private
44
44
 
45
45
  def inherited(subclass)
46
- super
47
46
  subclass.class_eval do
48
47
  @to_non_null_type ||= nil
49
48
  @to_list_type ||= nil
50
49
  end
50
+ super
51
51
  end
52
52
  end
53
53
  end
@@ -81,7 +81,7 @@ module GraphQL
81
81
 
82
82
  error
83
83
  else
84
- yield
84
+ super
85
85
  end
86
86
  end
87
87
  end
@@ -147,7 +147,12 @@ module GraphQL
147
147
  if new_class
148
148
  @trace_class = new_class
149
149
  elsif !defined?(@trace_class)
150
- @trace_class = Class.new(GraphQL::Tracing::Trace)
150
+ parent_trace_class = if superclass.respond_to?(:trace_class)
151
+ superclass.trace_class
152
+ else
153
+ GraphQL::Tracing::Trace
154
+ end
155
+ @trace_class = Class.new(parent_trace_class)
151
156
  end
152
157
  @trace_class
153
158
  end
@@ -794,11 +799,7 @@ module GraphQL
794
799
  end
795
800
 
796
801
  if resolved_type.nil? || (resolved_type.is_a?(Module) && resolved_type.respond_to?(:kind))
797
- if resolved_value
798
- [resolved_type, resolved_value]
799
- else
800
- resolved_type
801
- end
802
+ [resolved_type, resolved_value]
802
803
  else
803
804
  raise ".resolve_type should return a type definition, but got #{resolved_type.inspect} (#{resolved_type.class}) from `resolve_type(#{type}, #{obj}, #{ctx})`"
804
805
  end
@@ -955,14 +956,17 @@ module GraphQL
955
956
  # @param options [Hash] Keywords that will be passed to the tracing class during `#initialize`
956
957
  # @return [void]
957
958
  def trace_with(trace_mod, **options)
958
- @trace_options ||= {}
959
- @trace_options.merge!(options)
959
+ trace_options.merge!(options)
960
960
  trace_class.include(trace_mod)
961
961
  end
962
962
 
963
+ def trace_options
964
+ @trace_options ||= superclass.respond_to?(:trace_options) ? superclass.trace_options.dup : {}
965
+ end
966
+
963
967
  def new_trace(**options)
964
968
  if defined?(@trace_options)
965
- options = @trace_options.merge(options)
969
+ options = trace_options.merge(options)
966
970
  end
967
971
  trace_class.new(**options)
968
972
  end
@@ -5,7 +5,6 @@ module GraphQL
5
5
  module AppsignalTrace
6
6
  include PlatformTrace
7
7
 
8
-
9
8
  # @param set_action_name [Boolean] If true, the GraphQL operation name will be used as the transaction name.
10
9
  # This is not advised if you run more than one query per HTTP request, for example, with `graphql-client` or multiplexing.
11
10
  # It can also be specified per-query with `context[:set_appsignal_action_name]`.
@@ -46,7 +45,13 @@ module GraphQL
46
45
 
47
46
  def platform_execute_field(platform_key)
48
47
  Appsignal.instrument(platform_key) do
49
- super
48
+ yield
49
+ end
50
+ end
51
+
52
+ def platform_authorized(platform_key)
53
+ Appsignal.instrument(platform_key) do
54
+ yield
50
55
  end
51
56
  end
52
57
 
@@ -35,7 +35,7 @@ module GraphQL
35
35
  # # Alternatively, you can call the class methods followed by your edge type
36
36
  # # edges_nullable true
37
37
  # # edge_nullable true
38
- # # nodes_nullable true
38
+ # # node_nullable true
39
39
  # # has_nodes_field true
40
40
  # # edge_type Types::PostEdge
41
41
  # end
@@ -9,16 +9,34 @@ module GraphQL
9
9
 
10
10
  def self.included(child_class)
11
11
  child_class.extend(ClassMethods)
12
- child_class.extend(Relay::DefaultRelay)
13
- child_class.default_relay(true)
14
12
  child_class.has_nodes_field(true)
15
13
  child_class.node_nullable(true)
16
14
  child_class.edges_nullable(true)
17
15
  child_class.edge_nullable(true)
16
+ child_class.module_eval {
17
+ self.edge_type = nil
18
+ self.node_type = nil
19
+ self.edge_class = nil
20
+ }
18
21
  add_page_info_field(child_class)
19
22
  end
20
23
 
21
24
  module ClassMethods
25
+ def inherited(child_class)
26
+ super
27
+ child_class.has_nodes_field(has_nodes_field)
28
+ child_class.node_nullable(node_nullable)
29
+ child_class.edges_nullable(edges_nullable)
30
+ child_class.edge_nullable(edge_nullable)
31
+ child_class.edge_type = nil
32
+ child_class.node_type = nil
33
+ child_class.edge_class = nil
34
+ end
35
+
36
+ def default_relay?
37
+ true
38
+ end
39
+
22
40
  # @return [Class]
23
41
  attr_reader :node_type
24
42
 
@@ -124,6 +142,10 @@ module GraphQL
124
142
  end
125
143
  end
126
144
 
145
+ protected
146
+
147
+ attr_writer :edge_type, :node_type, :edge_class
148
+
127
149
  private
128
150
 
129
151
  def define_nodes_field(nullable, field_options: nil)
@@ -8,11 +8,21 @@ module GraphQL
8
8
  child_class.description("An edge in a connection.")
9
9
  child_class.field(:cursor, String, null: false, description: "A cursor for use in pagination.")
10
10
  child_class.extend(ClassMethods)
11
- child_class.extend(GraphQL::Types::Relay::DefaultRelay)
11
+ child_class.class_eval { self.node_type = nil }
12
12
  child_class.node_nullable(true)
13
13
  end
14
14
 
15
15
  module ClassMethods
16
+ def inherited(child_class)
17
+ super
18
+ child_class.node_type = nil
19
+ child_class.node_nullable = nil
20
+ end
21
+
22
+ def default_relay?
23
+ true
24
+ end
25
+
16
26
  # Get or set the Object type that this edge wraps.
17
27
  #
18
28
  # @param node_type [Class] A `Schema::Object` subclass
@@ -49,11 +59,15 @@ module GraphQL
49
59
  # Use `node_nullable(false)` in your base class to make non-null `node` field.
50
60
  def node_nullable(new_value = nil)
51
61
  if new_value.nil?
52
- defined?(@node_nullable) ? @node_nullable : superclass.node_nullable
62
+ @node_nullable != nil ? @node_nullable : superclass.node_nullable
53
63
  else
54
64
  @node_nullable = new_value
55
65
  end
56
66
  end
67
+
68
+ protected
69
+
70
+ attr_writer :node_type, :node_nullable
57
71
  end
58
72
  end
59
73
  end
@@ -5,7 +5,7 @@ module GraphQL
5
5
  module Relay
6
6
  module NodeBehaviors
7
7
  def self.included(child_module)
8
- child_module.extend(DefaultRelay)
8
+ child_module.extend(ClassMethods)
9
9
  child_module.description("An object with an ID.")
10
10
  child_module.field(:id, ID, null: false, description: "ID of the object.", resolver_method: :default_global_id)
11
11
  end
@@ -13,6 +13,12 @@ module GraphQL
13
13
  def default_global_id
14
14
  context.schema.id_from_object(object, self.class, context)
15
15
  end
16
+
17
+ module ClassMethods
18
+ def default_relay?
19
+ true
20
+ end
21
+ end
16
22
  end
17
23
  end
18
24
  end
@@ -4,8 +4,7 @@ module GraphQL
4
4
  module Relay
5
5
  module PageInfoBehaviors
6
6
  def self.included(child_class)
7
- child_class.extend GraphQL::Types::Relay::DefaultRelay
8
-
7
+ child_class.extend ClassMethods
9
8
  child_class.description "Information about pagination in a connection."
10
9
  child_class.field :has_next_page, Boolean, null: false,
11
10
  description: "When paginating forwards, are there more items?"
@@ -20,6 +19,12 @@ module GraphQL
20
19
  description: "When paginating forwards, the cursor to continue."
21
20
  end
22
21
  end
22
+
23
+ module ClassMethods
24
+ def default_relay?
25
+ true
26
+ end
27
+ end
23
28
  end
24
29
  end
25
30
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # behavior modules:
4
- require "graphql/types/relay/default_relay"
5
4
  require "graphql/types/relay/connection_behaviors"
6
5
  require "graphql/types/relay/edge_behaviors"
7
6
  require "graphql/types/relay/node_behaviors"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "2.0.18"
3
+ VERSION = "2.0.20"
4
4
  end
data/lib/graphql.rb CHANGED
@@ -43,7 +43,7 @@ This is probably a bug in GraphQL-Ruby, please report this error on GitHub: http
43
43
  # @param graphql_string [String] a GraphQL query string or schema definition
44
44
  # @return [GraphQL::Language::Nodes::Document]
45
45
  def self.parse(graphql_string, trace: GraphQL::Tracing::NullTrace)
46
- parse_with_racc(graphql_string, trace: trace)
46
+ default_parser.parse(graphql_string, trace: trace)
47
47
  end
48
48
 
49
49
  # Read the contents of `filename` and parse them as GraphQL
@@ -51,15 +51,19 @@ This is probably a bug in GraphQL-Ruby, please report this error on GitHub: http
51
51
  # @return [GraphQL::Language::Nodes::Document]
52
52
  def self.parse_file(filename)
53
53
  content = File.read(filename)
54
- parse_with_racc(content, filename: filename)
54
+ default_parser.parse(content, filename: filename)
55
+ end
56
+
57
+ # @return [Array<Array>]
58
+ def self.scan(graphql_string)
59
+ default_parser.scan(graphql_string)
55
60
  end
56
61
 
57
62
  def self.parse_with_racc(string, filename: nil, trace: GraphQL::Tracing::NullTrace)
58
63
  GraphQL::Language::Parser.parse(string, filename: filename, trace: trace)
59
64
  end
60
65
 
61
- # @return [Array<GraphQL::Language::Token>]
62
- def self.scan(graphql_string)
66
+ def self.scan_with_ruby(graphql_string)
63
67
  GraphQL::Language::Lexer.tokenize(graphql_string)
64
68
  end
65
69
 
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.0.18
4
+ version: 2.0.20
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-03-09 00:00:00.000000000 Z
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -112,16 +112,30 @@ dependencies:
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '12'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '12'
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake-compiler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rubocop
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -317,7 +331,6 @@ files:
317
331
  - lib/graphql/execution/multiplex.rb
318
332
  - lib/graphql/execution_error.rb
319
333
  - lib/graphql/filter.rb
320
- - lib/graphql/graphql_ext.bundle
321
334
  - lib/graphql/integer_decoding_error.rb
322
335
  - lib/graphql/integer_encoding_error.rb
323
336
  - lib/graphql/introspection.rb
@@ -342,7 +355,6 @@ files:
342
355
  - lib/graphql/language/document_from_schema_definition.rb
343
356
  - lib/graphql/language/generation.rb
344
357
  - lib/graphql/language/lexer.rb
345
- - lib/graphql/language/lexer.ri
346
358
  - lib/graphql/language/nodes.rb
347
359
  - lib/graphql/language/parser.rb
348
360
  - lib/graphql/language/parser.y
@@ -570,7 +582,6 @@ files:
570
582
  - lib/graphql/types/relay/base_connection.rb
571
583
  - lib/graphql/types/relay/base_edge.rb
572
584
  - lib/graphql/types/relay/connection_behaviors.rb
573
- - lib/graphql/types/relay/default_relay.rb
574
585
  - lib/graphql/types/relay/edge_behaviors.rb
575
586
  - lib/graphql/types/relay/has_node_field.rb
576
587
  - lib/graphql/types/relay/has_nodes_field.rb
Binary file