graphql 2.0.16 → 2.0.21

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.

Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/analysis/ast/visitor.rb +42 -35
  3. data/lib/graphql/analysis/ast.rb +2 -2
  4. data/lib/graphql/backtrace/trace.rb +96 -0
  5. data/lib/graphql/backtrace/tracer.rb +1 -1
  6. data/lib/graphql/backtrace.rb +6 -1
  7. data/lib/graphql/execution/interpreter/arguments.rb +1 -1
  8. data/lib/graphql/execution/interpreter/arguments_cache.rb +2 -3
  9. data/lib/graphql/execution/interpreter/resolve.rb +19 -0
  10. data/lib/graphql/execution/interpreter/runtime.rb +264 -211
  11. data/lib/graphql/execution/interpreter.rb +15 -10
  12. data/lib/graphql/execution/lazy.rb +6 -12
  13. data/lib/graphql/execution/multiplex.rb +2 -1
  14. data/lib/graphql/filter.rb +7 -2
  15. data/lib/graphql/introspection/directive_type.rb +2 -2
  16. data/lib/graphql/introspection/field_type.rb +1 -1
  17. data/lib/graphql/introspection/schema_type.rb +2 -2
  18. data/lib/graphql/introspection/type_type.rb +5 -5
  19. data/lib/graphql/language/document_from_schema_definition.rb +25 -9
  20. data/lib/graphql/language/lexer.rb +216 -1505
  21. data/lib/graphql/language/nodes.rb +66 -40
  22. data/lib/graphql/language/parser.rb +509 -491
  23. data/lib/graphql/language/parser.y +43 -38
  24. data/lib/graphql/language/visitor.rb +191 -83
  25. data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
  26. data/lib/graphql/pagination/connection.rb +5 -5
  27. data/lib/graphql/query/context.rb +62 -31
  28. data/lib/graphql/query/null_context.rb +1 -1
  29. data/lib/graphql/query.rb +22 -5
  30. data/lib/graphql/schema/argument.rb +7 -13
  31. data/lib/graphql/schema/build_from_definition.rb +15 -3
  32. data/lib/graphql/schema/directive.rb +12 -2
  33. data/lib/graphql/schema/enum.rb +24 -17
  34. data/lib/graphql/schema/enum_value.rb +2 -3
  35. data/lib/graphql/schema/field.rb +68 -57
  36. data/lib/graphql/schema/field_extension.rb +1 -4
  37. data/lib/graphql/schema/find_inherited_value.rb +2 -7
  38. data/lib/graphql/schema/interface.rb +0 -10
  39. data/lib/graphql/schema/late_bound_type.rb +2 -0
  40. data/lib/graphql/schema/member/base_dsl_methods.rb +17 -14
  41. data/lib/graphql/schema/member/has_arguments.rb +105 -58
  42. data/lib/graphql/schema/member/has_ast_node.rb +12 -0
  43. data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
  44. data/lib/graphql/schema/member/has_directives.rb +15 -10
  45. data/lib/graphql/schema/member/has_fields.rb +95 -38
  46. data/lib/graphql/schema/member/has_interfaces.rb +49 -8
  47. data/lib/graphql/schema/member/has_validators.rb +32 -6
  48. data/lib/graphql/schema/member/relay_shortcuts.rb +19 -0
  49. data/lib/graphql/schema/member/type_system_helpers.rb +17 -0
  50. data/lib/graphql/schema/object.rb +2 -4
  51. data/lib/graphql/schema/resolver/has_payload_type.rb +9 -9
  52. data/lib/graphql/schema/resolver.rb +4 -4
  53. data/lib/graphql/schema/timeout.rb +24 -28
  54. data/lib/graphql/schema/validator.rb +1 -1
  55. data/lib/graphql/schema/warden.rb +29 -5
  56. data/lib/graphql/schema.rb +76 -25
  57. data/lib/graphql/static_validation/literal_validator.rb +15 -1
  58. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
  59. data/lib/graphql/static_validation/rules/fields_will_merge.rb +2 -2
  60. data/lib/graphql/static_validation/validator.rb +1 -1
  61. data/lib/graphql/subscriptions/event.rb +2 -7
  62. data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
  63. data/lib/graphql/tracing/appoptics_trace.rb +231 -0
  64. data/lib/graphql/tracing/appsignal_trace.rb +77 -0
  65. data/lib/graphql/tracing/data_dog_trace.rb +148 -0
  66. data/lib/graphql/tracing/legacy_trace.rb +65 -0
  67. data/lib/graphql/tracing/new_relic_trace.rb +75 -0
  68. data/lib/graphql/tracing/notifications_trace.rb +42 -0
  69. data/lib/graphql/tracing/platform_trace.rb +109 -0
  70. data/lib/graphql/tracing/platform_tracing.rb +15 -3
  71. data/lib/graphql/tracing/prometheus_trace.rb +89 -0
  72. data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +1 -1
  73. data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
  74. data/lib/graphql/tracing/scout_trace.rb +72 -0
  75. data/lib/graphql/tracing/statsd_trace.rb +56 -0
  76. data/lib/graphql/tracing/trace.rb +75 -0
  77. data/lib/graphql/tracing.rb +16 -39
  78. data/lib/graphql/type_kinds.rb +6 -3
  79. data/lib/graphql/types/relay/base_connection.rb +1 -1
  80. data/lib/graphql/types/relay/connection_behaviors.rb +24 -6
  81. data/lib/graphql/types/relay/edge_behaviors.rb +16 -6
  82. data/lib/graphql/types/relay/node_behaviors.rb +7 -1
  83. data/lib/graphql/types/relay/page_info_behaviors.rb +7 -2
  84. data/lib/graphql/types/relay.rb +0 -1
  85. data/lib/graphql/types/string.rb +1 -1
  86. data/lib/graphql/version.rb +1 -1
  87. data/lib/graphql.rb +16 -9
  88. metadata +34 -9
  89. data/lib/graphql/language/lexer.rl +0 -280
  90. data/lib/graphql/types/relay/default_relay.rb +0 -27
@@ -91,22 +91,31 @@ module GraphQL
91
91
  end
92
92
 
93
93
  class ScopedContext
94
+ NO_PATH = GraphQL::EmptyObjects::EMPTY_ARRAY
95
+ NO_CONTEXT = GraphQL::EmptyObjects::EMPTY_HASH
96
+
94
97
  def initialize(query_context)
95
98
  @query_context = query_context
96
- @scoped_contexts = {}
97
- @no_path = [].freeze
99
+ @scoped_contexts = nil
100
+ @all_keys = nil
98
101
  end
99
102
 
100
103
  def merged_context
101
- merged_ctx = {}
102
- each_present_path_ctx do |path_ctx|
103
- 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
104
112
  end
105
- merged_ctx
106
113
  end
107
114
 
108
115
  def merge!(hash)
109
- ctx = @scoped_contexts
116
+ @all_keys ||= Set.new
117
+ @all_keys.merge(hash.keys)
118
+ ctx = @scoped_contexts ||= {}
110
119
  current_path.each do |path_part|
111
120
  ctx = ctx[path_part] ||= { parent: ctx }
112
121
  end
@@ -114,15 +123,12 @@ module GraphQL
114
123
  this_scoped_ctx.merge!(hash)
115
124
  end
116
125
 
117
- def current_path
118
- thread_info = Thread.current[:__graphql_runtime_info]
119
- (thread_info && thread_info[:current_path]) || @no_path
120
- end
121
-
122
126
  def key?(key)
123
- each_present_path_ctx do |path_ctx|
124
- if path_ctx.key?(key)
125
- return true
127
+ if @all_keys && @all_keys.include?(key)
128
+ each_present_path_ctx do |path_ctx|
129
+ if path_ctx.key?(key)
130
+ return true
131
+ end
126
132
  end
127
133
  end
128
134
  false
@@ -137,6 +143,10 @@ module GraphQL
137
143
  nil
138
144
  end
139
145
 
146
+ def current_path
147
+ @query_context.current_path || NO_PATH
148
+ end
149
+
140
150
  def dig(key, *other_keys)
141
151
  each_present_path_ctx do |path_ctx|
142
152
  if path_ctx.key?(key)
@@ -157,19 +167,23 @@ module GraphQL
157
167
  # but look up the tree for previously-assigned scoped values
158
168
  def each_present_path_ctx
159
169
  ctx = @scoped_contexts
160
- current_path.each do |path_part|
161
- if ctx.key?(path_part)
162
- ctx = ctx[path_part]
163
- else
164
- 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
165
179
  end
166
- end
167
180
 
168
- while ctx
169
- if (scoped_ctx = ctx[:scoped_context])
170
- yield(scoped_ctx)
181
+ while ctx
182
+ if (scoped_ctx = ctx[:scoped_context])
183
+ yield(scoped_ctx)
184
+ end
185
+ ctx = ctx[:parent]
171
186
  end
172
- ctx = ctx[:parent]
173
187
  end
174
188
  end
175
189
  end
@@ -209,14 +223,30 @@ module GraphQL
209
223
  elsif @provided_values.key?(key)
210
224
  @provided_values[key]
211
225
  elsif RUNTIME_METADATA_KEYS.include?(key)
212
- thread_info = Thread.current[:__graphql_runtime_info]
213
- thread_info && thread_info[key]
226
+ if key == :current_path
227
+ current_path
228
+ else
229
+ (current_runtime_state = Thread.current[:__graphql_runtime_info]) &&
230
+ (current_runtime_state.public_send(key))
231
+ end
214
232
  else
215
233
  # not found
216
234
  nil
217
235
  end
218
236
  end
219
237
 
238
+ def current_path
239
+ current_runtime_state = Thread.current[:__graphql_runtime_info]
240
+ path = current_runtime_state &&
241
+ (result = current_runtime_state.current_result) &&
242
+ (result.path)
243
+ if path && (rn = current_runtime_state.current_result_name)
244
+ path = path.dup
245
+ path.push(rn)
246
+ end
247
+ path
248
+ end
249
+
220
250
  def delete(key)
221
251
  if @scoped_context.key?(key)
222
252
  @scoped_context.delete(key)
@@ -229,8 +259,8 @@ module GraphQL
229
259
 
230
260
  def fetch(key, default = UNSPECIFIED_FETCH_DEFAULT)
231
261
  if RUNTIME_METADATA_KEYS.include?(key)
232
- (thread_info = Thread.current[:__graphql_runtime_info]) &&
233
- thread_info[key]
262
+ (runtime = Thread.current[:__graphql_runtime_info]) &&
263
+ (runtime.public_send(key))
234
264
  elsif @scoped_context.key?(key)
235
265
  scoped_context[key]
236
266
  elsif @provided_values.key?(key)
@@ -246,8 +276,9 @@ module GraphQL
246
276
 
247
277
  def dig(key, *other_keys)
248
278
  if RUNTIME_METADATA_KEYS.include?(key)
249
- (thread_info = Thread.current[:__graphql_runtime_info]).key?(key) &&
250
- thread_info.dig(key, *other_keys)
279
+ (current_runtime_state = Thread.current[:__graphql_runtime_info]) &&
280
+ (obj = current_runtime_state.public_send(key)) &&
281
+ obj.dig(*other_keys)
251
282
  elsif @scoped_context.key?(key)
252
283
  @scoped_context.dig(key, *other_keys)
253
284
  else
@@ -24,7 +24,7 @@ module GraphQL
24
24
  @dataloader = GraphQL::Dataloader::NullDataloader.new
25
25
  @schema = NullSchema
26
26
  @warden = NullWarden.new(
27
- GraphQL::Filter.new,
27
+ GraphQL::Filter.new(silence_deprecation_warning: true),
28
28
  context: self,
29
29
  schema: @schema,
30
30
  )
data/lib/graphql/query.rb CHANGED
@@ -95,12 +95,24 @@ module GraphQL
95
95
  @fragments = nil
96
96
  @operations = nil
97
97
  @validate = validate
98
- @tracers = schema.tracers + (context ? context.fetch(:tracers, []) : [])
98
+ context_tracers = (context ? context.fetch(:tracers, []) : [])
99
+ @tracers = schema.tracers + context_tracers
100
+
99
101
  # Support `ctx[:backtrace] = true` for wrapping backtraces
100
102
  if context && context[:backtrace] && !@tracers.include?(GraphQL::Backtrace::Tracer)
101
- @tracers << GraphQL::Backtrace::Tracer
103
+ if schema.trace_class <= GraphQL::Tracing::LegacyTrace
104
+ context_tracers += [GraphQL::Backtrace::Tracer]
105
+ @tracers << GraphQL::Backtrace::Tracer
106
+ elsif !(current_trace.class <= GraphQL::Backtrace::Trace)
107
+ 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."
108
+ end
109
+ end
110
+
111
+ if context_tracers.any? && !(schema.trace_class <= GraphQL::Tracing::LegacyTrace)
112
+ raise ArgumentError, "context[:tracers] are not supported without `trace_class(GraphQL::Tracing::LegacyTrace)` in the schema configuration, please add it."
102
113
  end
103
114
 
115
+
104
116
  @analysis_errors = []
105
117
  if variables.is_a?(String)
106
118
  raise ArgumentError, "Query variables should be a Hash, not a String. Try JSON.parse to prepare variables."
@@ -157,6 +169,11 @@ module GraphQL
157
169
 
158
170
  attr_accessor :multiplex
159
171
 
172
+ # @return [GraphQL::Tracing::Trace]
173
+ def current_trace
174
+ @current_trace ||= multiplex ? multiplex.current_trace : schema.new_trace(multiplex: multiplex, query: self)
175
+ end
176
+
160
177
  def subscription_update?
161
178
  @subscription_topic && subscription?
162
179
  end
@@ -305,8 +322,8 @@ module GraphQL
305
322
  # @param value [Object] Any runtime value
306
323
  # @return [GraphQL::ObjectType, nil] The runtime type of `value` from {Schema#resolve_type}
307
324
  # @see {#possible_types} to apply filtering from `only` / `except`
308
- def resolve_type(abstract_type, value = :__undefined__)
309
- if value.is_a?(Symbol) && value == :__undefined__
325
+ def resolve_type(abstract_type, value = NOT_CONFIGURED)
326
+ if value.is_a?(Symbol) && value == NOT_CONFIGURED
310
327
  # Old method signature
311
328
  value = abstract_type
312
329
  abstract_type = nil
@@ -362,7 +379,7 @@ module GraphQL
362
379
  parse_error = nil
363
380
  @document ||= begin
364
381
  if query_string
365
- GraphQL.parse(query_string, tracer: self)
382
+ GraphQL.parse(query_string, trace: self.current_trace)
366
383
  end
367
384
  rescue GraphQL::ParseError => err
368
385
  parse_error = err
@@ -7,9 +7,7 @@ module GraphQL
7
7
  include GraphQL::Schema::Member::HasDirectives
8
8
  include GraphQL::Schema::Member::HasDeprecationReason
9
9
  include GraphQL::Schema::Member::HasValidators
10
- include GraphQL::Schema::FindInheritedValue::EmptyObjects
11
-
12
- NO_DEFAULT = :__no_default__
10
+ include GraphQL::EmptyObjects
13
11
 
14
12
  # @return [String] the GraphQL name for this argument, camelized unless `camelize: false` is provided
15
13
  attr_reader :name
@@ -20,8 +18,8 @@ module GraphQL
20
18
 
21
19
  # @param new_prepare [Method, Proc]
22
20
  # @return [Symbol] A method or proc to call to transform this value before sending it to field resolution method
23
- def prepare(new_prepare = NO_DEFAULT)
24
- if new_prepare != NO_DEFAULT
21
+ def prepare(new_prepare = NOT_CONFIGURED)
22
+ if new_prepare != NOT_CONFIGURED
25
23
  @prepare = new_prepare
26
24
  end
27
25
  @prepare
@@ -52,7 +50,7 @@ module GraphQL
52
50
  # @param deprecation_reason [String]
53
51
  # @param validates [Hash, nil] Options for building validators, if any should be applied
54
52
  # @param replace_null_with_default [Boolean] if `true`, incoming values of `null` will be replaced with the configured `default_value`
55
- def initialize(arg_name = nil, type_expr = nil, desc = nil, required: true, type: nil, name: nil, loads: nil, description: nil, ast_node: nil, default_value: NO_DEFAULT, as: nil, from_resolver: false, camelize: true, prepare: nil, owner:, validates: nil, directives: nil, deprecation_reason: nil, replace_null_with_default: false, &definition_block)
53
+ def initialize(arg_name = nil, type_expr = nil, desc = nil, required: true, type: nil, name: nil, loads: nil, description: nil, ast_node: nil, default_value: NOT_CONFIGURED, as: nil, from_resolver: false, camelize: true, prepare: nil, owner:, validates: nil, directives: nil, deprecation_reason: nil, replace_null_with_default: false, &definition_block)
56
54
  arg_name ||= name
57
55
  @name = -(camelize ? Member::BuildType.camelize(arg_name.to_s) : arg_name.to_s)
58
56
  @type_expr = type_expr || type
@@ -104,8 +102,8 @@ module GraphQL
104
102
 
105
103
  # @param default_value [Object] The value to use when the client doesn't provide one
106
104
  # @return [Object] the value used when the client doesn't provide a value for this argument
107
- def default_value(new_default_value = NO_DEFAULT)
108
- if new_default_value != NO_DEFAULT
105
+ def default_value(new_default_value = NOT_CONFIGURED)
106
+ if new_default_value != NOT_CONFIGURED
109
107
  @default_value = new_default_value
110
108
  end
111
109
  @default_value
@@ -113,7 +111,7 @@ module GraphQL
113
111
 
114
112
  # @return [Boolean] True if this argument has a default value
115
113
  def default_value?
116
- @default_value != NO_DEFAULT
114
+ @default_value != NOT_CONFIGURED
117
115
  end
118
116
 
119
117
  def replace_null_with_default?
@@ -149,10 +147,6 @@ module GraphQL
149
147
  true
150
148
  end
151
149
 
152
- def accessible?(context)
153
- true
154
- end
155
-
156
150
  def authorized?(obj, value, ctx)
157
151
  authorized_as_type?(obj, value, ctx, as_type: type)
158
152
  end
@@ -21,6 +21,7 @@ module GraphQL
21
21
 
22
22
  # @api private
23
23
  module Builder
24
+ include GraphQL::EmptyObjects
24
25
  extend self
25
26
 
26
27
  def build(schema_superclass, document, default_resolve:, using: {}, relay:)
@@ -99,6 +100,16 @@ module GraphQL
99
100
  raise InvalidDocumentError.new("Specified subscription type \"#{schema_definition.subscription}\" not found in document.") unless types[schema_definition.subscription]
100
101
  subscription_root_type = types[schema_definition.subscription]
101
102
  end
103
+
104
+ if schema_definition.query.nil? &&
105
+ schema_definition.mutation.nil? &&
106
+ schema_definition.subscription.nil?
107
+ # This schema may have been given with directives only,
108
+ # check for defaults:
109
+ query_root_type = types['Query']
110
+ mutation_root_type = types['Mutation']
111
+ subscription_root_type = types['Subscription']
112
+ end
102
113
  else
103
114
  query_root_type = types['Query']
104
115
  mutation_root_type = types['Mutation']
@@ -107,6 +118,8 @@ module GraphQL
107
118
 
108
119
  raise InvalidDocumentError.new('Must provide schema definition with query type or a type named Query.') unless query_root_type
109
120
 
121
+ builder = self
122
+
110
123
  schema_class = Class.new(schema_superclass) do
111
124
  begin
112
125
  # Add these first so that there's some chance of resolving late-bound types
@@ -134,6 +147,7 @@ module GraphQL
134
147
 
135
148
  if schema_definition
136
149
  ast_node(schema_definition)
150
+ builder.build_directives(self, schema_definition, type_resolver)
137
151
  end
138
152
 
139
153
  using.each do |plugin, options|
@@ -361,8 +375,6 @@ module GraphQL
361
375
  end
362
376
  end
363
377
 
364
- NO_DEFAULT_VALUE = {}.freeze
365
-
366
378
  def build_arguments(type_class, arguments, type_resolver)
367
379
  builder = self
368
380
 
@@ -370,7 +382,7 @@ module GraphQL
370
382
  default_value_kwargs = if !argument_defn.default_value.nil?
371
383
  { default_value: builder.build_default_value(argument_defn.default_value) }
372
384
  else
373
- NO_DEFAULT_VALUE
385
+ EMPTY_HASH
374
386
  end
375
387
 
376
388
  type_class.argument(
@@ -8,6 +8,7 @@ module GraphQL
8
8
  # - {.resolve}: Wraps field resolution (so it should call `yield` to continue)
9
9
  class Directive < GraphQL::Schema::Member
10
10
  extend GraphQL::Schema::Member::HasArguments
11
+ extend GraphQL::Schema::Member::HasArguments::HasDirectiveArguments
11
12
 
12
13
  class << self
13
14
  # Directives aren't types, they don't have kinds.
@@ -21,9 +22,9 @@ module GraphQL
21
22
  # but downcase the first letter.
22
23
  def default_graphql_name
23
24
  @default_graphql_name ||= begin
24
- camelized_name = super
25
+ camelized_name = super.dup
25
26
  camelized_name[0] = camelized_name[0].downcase
26
- camelized_name
27
+ -camelized_name
27
28
  end
28
29
  end
29
30
 
@@ -93,6 +94,15 @@ module GraphQL
93
94
  def repeatable(new_value)
94
95
  @repeatable = new_value
95
96
  end
97
+
98
+ private
99
+
100
+ def inherited(subclass)
101
+ super
102
+ subclass.class_eval do
103
+ @default_graphql_name ||= nil
104
+ end
105
+ end
96
106
  end
97
107
 
98
108
  # @return [GraphQL::Schema::Field, GraphQL::Schema::Argument, Class, Module]
@@ -1,24 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphQL
4
- # Extend this class to define GraphQL enums in your schema.
5
- #
6
- # By default, GraphQL enum values are translated into Ruby strings.
7
- # You can provide a custom value with the `value:` keyword.
8
- #
9
- # @example
10
- # # equivalent to
11
- # # enum PizzaTopping {
12
- # # MUSHROOMS
13
- # # ONIONS
14
- # # PEPPERS
15
- # # }
16
- # class PizzaTopping < GraphQL::Enum
17
- # value :MUSHROOMS
18
- # value :ONIONS
19
- # value :PEPPERS
20
- # end
21
4
  class Schema
5
+ # Extend this class to define GraphQL enums in your schema.
6
+ #
7
+ # By default, GraphQL enum values are translated into Ruby strings.
8
+ # You can provide a custom value with the `value:` keyword.
9
+ #
10
+ # @example
11
+ # # equivalent to
12
+ # # enum PizzaTopping {
13
+ # # MUSHROOMS
14
+ # # ONIONS
15
+ # # PEPPERS
16
+ # # }
17
+ # class PizzaTopping < GraphQL::Enum
18
+ # value :MUSHROOMS
19
+ # value :ONIONS
20
+ # value :PEPPERS
21
+ # end
22
22
  class Enum < GraphQL::Schema::Member
23
23
  extend GraphQL::Schema::Member::ValidatesInput
24
24
 
@@ -34,6 +34,13 @@ module GraphQL
34
34
  end
35
35
  end
36
36
 
37
+ class MissingValuesError < GraphQL::Error
38
+ def initialize(enum_type)
39
+ @enum_type = enum_type
40
+ super("Enum types require at least one value, but #{enum_type.graphql_name} didn't provide any for this query. Make sure at least one value is defined and visible for this query.")
41
+ end
42
+ end
43
+
37
44
  class << self
38
45
  # Define a value for this enum
39
46
  # @param graphql_name [String, Symbol] the GraphQL value for this, usually `SCREAMING_CASE`
@@ -30,11 +30,11 @@ module GraphQL
30
30
  # @return [Class] The enum type that owns this value
31
31
  attr_reader :owner
32
32
 
33
- def initialize(graphql_name, desc = nil, owner:, ast_node: nil, directives: nil, description: nil, value: nil, deprecation_reason: nil, &block)
33
+ def initialize(graphql_name, desc = nil, owner:, ast_node: nil, directives: nil, description: nil, value: NOT_CONFIGURED, deprecation_reason: nil, &block)
34
34
  @graphql_name = graphql_name.to_s
35
35
  GraphQL::NameValidator.validate!(@graphql_name)
36
36
  @description = desc || description
37
- @value = value.nil? ? @graphql_name : value
37
+ @value = value === NOT_CONFIGURED ? @graphql_name : value
38
38
  if deprecation_reason
39
39
  self.deprecation_reason = deprecation_reason
40
40
  end
@@ -70,7 +70,6 @@ module GraphQL
70
70
  end
71
71
 
72
72
  def visible?(_ctx); true; end
73
- def accessible?(_ctx); true; end
74
73
  def authorized?(_ctx); true; end
75
74
  end
76
75
  end