graphql 2.0.13 → 2.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/install/mutation_root_generator.rb +2 -2
- data/lib/generators/graphql/install/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/install/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/install_generator.rb +3 -0
- data/lib/generators/graphql/mutation_delete_generator.rb +1 -1
- data/lib/generators/graphql/mutation_update_generator.rb +1 -1
- data/lib/generators/graphql/relay.rb +18 -1
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- data/lib/generators/graphql/templates/base_connection.erb +2 -0
- data/lib/generators/graphql/templates/base_edge.erb +2 -0
- data/lib/generators/graphql/templates/base_enum.erb +2 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +2 -0
- data/lib/generators/graphql/templates/base_interface.erb +2 -0
- data/lib/generators/graphql/templates/base_object.erb +2 -0
- data/lib/generators/graphql/templates/base_resolver.erb +6 -0
- data/lib/generators/graphql/templates/base_scalar.erb +2 -0
- data/lib/generators/graphql/templates/base_union.erb +2 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +2 -0
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +2 -0
- data/lib/generators/graphql/templates/node_type.erb +2 -0
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +8 -0
- data/lib/graphql/analysis/analyzer.rb +89 -0
- data/lib/graphql/analysis/field_usage.rb +82 -0
- data/lib/graphql/analysis/max_query_complexity.rb +20 -0
- data/lib/graphql/analysis/max_query_depth.rb +20 -0
- data/lib/graphql/analysis/query_complexity.rb +183 -0
- data/lib/graphql/analysis/query_depth.rb +58 -0
- data/lib/graphql/analysis/visitor.rb +283 -0
- data/lib/graphql/analysis.rb +92 -1
- data/lib/graphql/backtrace/inspect_result.rb +0 -12
- data/lib/graphql/backtrace/table.rb +2 -2
- data/lib/graphql/backtrace/trace.rb +93 -0
- data/lib/graphql/backtrace/tracer.rb +1 -1
- data/lib/graphql/backtrace.rb +2 -1
- data/lib/graphql/coercion_error.rb +1 -9
- data/lib/graphql/dataloader/async_dataloader.rb +88 -0
- data/lib/graphql/dataloader/null_dataloader.rb +1 -1
- data/lib/graphql/dataloader/request.rb +5 -0
- data/lib/graphql/dataloader/source.rb +89 -45
- data/lib/graphql/dataloader.rb +115 -142
- data/lib/graphql/duration_encoding_error.rb +16 -0
- data/lib/graphql/execution/interpreter/argument_value.rb +5 -1
- data/lib/graphql/execution/interpreter/arguments.rb +1 -1
- data/lib/graphql/execution/interpreter/arguments_cache.rb +33 -33
- data/lib/graphql/execution/interpreter/resolve.rb +19 -0
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +175 -0
- data/lib/graphql/execution/interpreter/runtime.rb +331 -455
- data/lib/graphql/execution/interpreter.rb +125 -61
- data/lib/graphql/execution/lazy.rb +6 -12
- data/lib/graphql/execution/lookahead.rb +124 -46
- data/lib/graphql/execution/multiplex.rb +3 -117
- data/lib/graphql/execution.rb +0 -1
- data/lib/graphql/introspection/directive_type.rb +3 -3
- data/lib/graphql/introspection/dynamic_fields.rb +1 -1
- data/lib/graphql/introspection/entry_points.rb +11 -5
- data/lib/graphql/introspection/field_type.rb +2 -2
- data/lib/graphql/introspection/schema_type.rb +10 -13
- data/lib/graphql/introspection/type_type.rb +17 -10
- data/lib/graphql/introspection.rb +3 -2
- data/lib/graphql/language/block_string.rb +34 -18
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/document_from_schema_definition.rb +75 -59
- data/lib/graphql/language/lexer.rb +358 -1506
- data/lib/graphql/language/nodes.rb +166 -93
- data/lib/graphql/language/parser.rb +795 -1953
- data/lib/graphql/language/printer.rb +340 -160
- data/lib/graphql/language/sanitized_printer.rb +21 -23
- data/lib/graphql/language/static_visitor.rb +167 -0
- data/lib/graphql/language/visitor.rb +188 -141
- data/lib/graphql/language.rb +61 -1
- data/lib/graphql/load_application_object_failed_error.rb +5 -1
- data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
- data/lib/graphql/pagination/array_connection.rb +6 -6
- data/lib/graphql/pagination/connection.rb +33 -6
- data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -2
- data/lib/graphql/query/context/scoped_context.rb +101 -0
- data/lib/graphql/query/context.rb +117 -112
- data/lib/graphql/query/null_context.rb +12 -25
- data/lib/graphql/query/validation_pipeline.rb +6 -5
- data/lib/graphql/query/variables.rb +3 -3
- data/lib/graphql/query.rb +86 -30
- data/lib/graphql/railtie.rb +9 -6
- data/lib/graphql/rake_task.rb +29 -11
- data/lib/graphql/rubocop/graphql/base_cop.rb +1 -1
- data/lib/graphql/schema/addition.rb +59 -23
- data/lib/graphql/schema/always_visible.rb +11 -0
- data/lib/graphql/schema/argument.rb +55 -26
- data/lib/graphql/schema/base_64_encoder.rb +3 -5
- data/lib/graphql/schema/build_from_definition.rb +56 -32
- data/lib/graphql/schema/directive/one_of.rb +24 -0
- data/lib/graphql/schema/directive/specified_by.rb +14 -0
- data/lib/graphql/schema/directive/transform.rb +1 -1
- data/lib/graphql/schema/directive.rb +15 -3
- data/lib/graphql/schema/enum.rb +35 -24
- data/lib/graphql/schema/enum_value.rb +2 -3
- data/lib/graphql/schema/field/connection_extension.rb +2 -16
- data/lib/graphql/schema/field/scope_extension.rb +8 -1
- data/lib/graphql/schema/field.rb +147 -107
- data/lib/graphql/schema/field_extension.rb +1 -4
- data/lib/graphql/schema/find_inherited_value.rb +2 -7
- data/lib/graphql/schema/has_single_input_argument.rb +158 -0
- data/lib/graphql/schema/input_object.rb +47 -11
- data/lib/graphql/schema/interface.rb +15 -21
- data/lib/graphql/schema/introspection_system.rb +7 -17
- data/lib/graphql/schema/late_bound_type.rb +10 -0
- data/lib/graphql/schema/list.rb +2 -2
- data/lib/graphql/schema/loader.rb +2 -3
- data/lib/graphql/schema/member/base_dsl_methods.rb +18 -14
- data/lib/graphql/schema/member/build_type.rb +11 -3
- data/lib/graphql/schema/member/has_arguments.rb +170 -130
- data/lib/graphql/schema/member/has_ast_node.rb +12 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
- data/lib/graphql/schema/member/has_directives.rb +81 -61
- data/lib/graphql/schema/member/has_fields.rb +100 -38
- data/lib/graphql/schema/member/has_interfaces.rb +65 -10
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +5 -1
- data/lib/graphql/schema/member/has_validators.rb +32 -6
- data/lib/graphql/schema/member/relay_shortcuts.rb +19 -0
- data/lib/graphql/schema/member/scoped.rb +19 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +16 -0
- data/lib/graphql/schema/member/validates_input.rb +3 -3
- data/lib/graphql/schema/mutation.rb +7 -0
- data/lib/graphql/schema/object.rb +16 -5
- data/lib/graphql/schema/printer.rb +11 -8
- data/lib/graphql/schema/relay_classic_mutation.rb +7 -129
- data/lib/graphql/schema/resolver/has_payload_type.rb +9 -9
- data/lib/graphql/schema/resolver.rb +47 -32
- data/lib/graphql/schema/scalar.rb +3 -3
- data/lib/graphql/schema/subscription.rb +11 -4
- data/lib/graphql/schema/subset.rb +397 -0
- data/lib/graphql/schema/timeout.rb +25 -29
- data/lib/graphql/schema/type_expression.rb +2 -2
- data/lib/graphql/schema/type_membership.rb +3 -0
- data/lib/graphql/schema/union.rb +11 -2
- data/lib/graphql/schema/unique_within_type.rb +1 -1
- data/lib/graphql/schema/validator/all_validator.rb +60 -0
- data/lib/graphql/schema/validator.rb +4 -2
- data/lib/graphql/schema/warden.rb +238 -93
- data/lib/graphql/schema.rb +498 -103
- data/lib/graphql/static_validation/all_rules.rb +2 -1
- data/lib/graphql/static_validation/base_visitor.rb +7 -6
- data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
- data/lib/graphql/static_validation/literal_validator.rb +24 -7
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -2
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +10 -10
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -1
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +4 -4
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -5
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +18 -27
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/validation_context.rb +5 -5
- data/lib/graphql/static_validation/validator.rb +4 -1
- data/lib/graphql/static_validation.rb +0 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +11 -4
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
- data/lib/graphql/subscriptions/event.rb +11 -10
- data/lib/graphql/subscriptions/serialize.rb +2 -0
- data/lib/graphql/subscriptions.rb +20 -13
- data/lib/graphql/testing/helpers.rb +151 -0
- data/lib/graphql/testing.rb +2 -0
- data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
- data/lib/graphql/tracing/appoptics_trace.rb +251 -0
- data/lib/graphql/tracing/appoptics_tracing.rb +2 -2
- data/lib/graphql/tracing/appsignal_trace.rb +77 -0
- data/lib/graphql/tracing/data_dog_trace.rb +183 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +9 -21
- data/lib/graphql/{execution/instrumentation.rb → tracing/legacy_hooks_trace.rb} +10 -28
- data/lib/graphql/tracing/legacy_trace.rb +69 -0
- data/lib/graphql/tracing/new_relic_trace.rb +75 -0
- data/lib/graphql/tracing/notifications_trace.rb +45 -0
- data/lib/graphql/tracing/platform_trace.rb +118 -0
- data/lib/graphql/tracing/platform_tracing.rb +17 -3
- data/lib/graphql/tracing/{prometheus_tracing → prometheus_trace}/graphql_collector.rb +4 -2
- data/lib/graphql/tracing/prometheus_trace.rb +89 -0
- data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
- data/lib/graphql/tracing/scout_trace.rb +72 -0
- data/lib/graphql/tracing/sentry_trace.rb +112 -0
- data/lib/graphql/tracing/statsd_trace.rb +56 -0
- data/lib/graphql/tracing/trace.rb +76 -0
- data/lib/graphql/tracing.rb +20 -40
- data/lib/graphql/type_kinds.rb +7 -4
- data/lib/graphql/types/iso_8601_duration.rb +77 -0
- data/lib/graphql/types/relay/base_connection.rb +1 -1
- data/lib/graphql/types/relay/connection_behaviors.rb +68 -6
- data/lib/graphql/types/relay/edge_behaviors.rb +33 -5
- data/lib/graphql/types/relay/node_behaviors.rb +8 -2
- data/lib/graphql/types/relay/page_info_behaviors.rb +11 -2
- data/lib/graphql/types/relay.rb +0 -1
- data/lib/graphql/types/string.rb +1 -1
- data/lib/graphql/types.rb +1 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +27 -20
- data/readme.md +13 -3
- metadata +96 -47
- data/lib/graphql/analysis/ast/analyzer.rb +0 -84
- data/lib/graphql/analysis/ast/field_usage.rb +0 -57
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -22
- data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
- data/lib/graphql/analysis/ast/query_complexity.rb +0 -230
- data/lib/graphql/analysis/ast/query_depth.rb +0 -55
- data/lib/graphql/analysis/ast/visitor.rb +0 -269
- data/lib/graphql/analysis/ast.rb +0 -81
- data/lib/graphql/deprecation.rb +0 -9
- data/lib/graphql/filter.rb +0 -53
- data/lib/graphql/language/lexer.rl +0 -280
- data/lib/graphql/language/parser.y +0 -554
- data/lib/graphql/language/token.rb +0 -34
- data/lib/graphql/schema/base_64_bp.rb +0 -26
- data/lib/graphql/schema/invalid_type_error.rb +0 -7
- data/lib/graphql/static_validation/type_stack.rb +0 -216
- data/lib/graphql/subscriptions/instrumentation.rb +0 -28
- data/lib/graphql/types/relay/default_relay.rb +0 -21
@@ -2,6 +2,7 @@
|
|
2
2
|
module GraphQL
|
3
3
|
module Language
|
4
4
|
module Nodes
|
5
|
+
NONE = GraphQL::EmptyObjects::EMPTY_ARRAY
|
5
6
|
# {AbstractNode} is the base class for all nodes in a GraphQL AST.
|
6
7
|
#
|
7
8
|
# It provides some APIs for working with ASTs:
|
@@ -9,32 +10,39 @@ module GraphQL
|
|
9
10
|
# - `scalars` returns all scalar (Ruby) values attached to this one. Used for comparing nodes.
|
10
11
|
# - `to_query_string` turns an AST node into a GraphQL string
|
11
12
|
class AbstractNode
|
13
|
+
|
12
14
|
module DefinitionNode
|
13
15
|
# This AST node's {#line} returns the first line, which may be the description.
|
14
16
|
# @return [Integer] The first line of the definition (not the description)
|
15
17
|
attr_reader :definition_line
|
16
18
|
|
17
|
-
def initialize(
|
18
|
-
@definition_line =
|
19
|
-
super(
|
19
|
+
def initialize(definition_line: nil, **_rest)
|
20
|
+
@definition_line = definition_line
|
21
|
+
super(**_rest)
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
+
def marshal_dump
|
25
|
+
super << @definition_line
|
26
|
+
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def initialize(options = {})
|
29
|
-
if options.key?(:position_source)
|
30
|
-
position_source = options.delete(:position_source)
|
31
|
-
@line = position_source.line
|
32
|
-
@col = position_source.col
|
28
|
+
def marshal_load(values)
|
29
|
+
@definition_line = values.pop
|
30
|
+
super
|
33
31
|
end
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :filename
|
34
35
|
|
35
|
-
|
36
|
+
def line
|
37
|
+
@line ||= @source.line_at(@pos)
|
38
|
+
end
|
36
39
|
|
37
|
-
|
40
|
+
def col
|
41
|
+
@col ||= @source.column_at(@pos)
|
42
|
+
end
|
43
|
+
|
44
|
+
def definition_line
|
45
|
+
@definition_line ||= (@source && @definition_pos) ? @source.line_at(@definition_pos) : nil
|
38
46
|
end
|
39
47
|
|
40
48
|
# Value equality
|
@@ -46,7 +54,7 @@ module GraphQL
|
|
46
54
|
other.children == self.children
|
47
55
|
end
|
48
56
|
|
49
|
-
NO_CHILDREN =
|
57
|
+
NO_CHILDREN = GraphQL::EmptyObjects::EMPTY_ARRAY
|
50
58
|
|
51
59
|
# @return [Array<GraphQL::Language::Nodes::AbstractNode>] all nodes in the tree below this one
|
52
60
|
def children
|
@@ -141,18 +149,26 @@ module GraphQL
|
|
141
149
|
.gsub(/([a-z])([A-Z])/,'\1_\2') # insert underscores
|
142
150
|
.downcase # remove caps
|
143
151
|
|
144
|
-
child_class.module_eval <<-RUBY
|
152
|
+
child_class.module_eval <<-RUBY, __FILE__, __LINE__
|
145
153
|
def visit_method
|
146
154
|
:on_#{name_underscored}
|
147
155
|
end
|
148
156
|
|
149
157
|
class << self
|
150
158
|
attr_accessor :children_method_name
|
159
|
+
|
160
|
+
def visit_method
|
161
|
+
:on_#{name_underscored}
|
162
|
+
end
|
151
163
|
end
|
152
164
|
self.children_method_name = :#{name_underscored}s
|
153
165
|
RUBY
|
154
166
|
end
|
155
167
|
|
168
|
+
def children_of_type
|
169
|
+
@children_methods
|
170
|
+
end
|
171
|
+
|
156
172
|
private
|
157
173
|
|
158
174
|
# Name accessors which return lists of nodes,
|
@@ -183,8 +199,8 @@ module GraphQL
|
|
183
199
|
module_eval <<-RUBY, __FILE__, __LINE__
|
184
200
|
# Singular method: create a node with these options
|
185
201
|
# and return a new `self` which includes that node in this list.
|
186
|
-
def merge_#{method_name.to_s.sub(/s$/, "")}(node_opts)
|
187
|
-
merge(#{method_name}: #{method_name} + [#{node_type.name}.new(node_opts)])
|
202
|
+
def merge_#{method_name.to_s.sub(/s$/, "")}(**node_opts)
|
203
|
+
merge(#{method_name}: #{method_name} + [#{node_type.name}.new(**node_opts)])
|
188
204
|
end
|
189
205
|
RUBY
|
190
206
|
end
|
@@ -213,13 +229,14 @@ module GraphQL
|
|
213
229
|
end
|
214
230
|
|
215
231
|
if defined?(@scalar_methods)
|
216
|
-
if
|
217
|
-
|
232
|
+
if !@initialize_was_generated
|
233
|
+
@initialize_was_generated = true
|
234
|
+
generate_initialize
|
218
235
|
else
|
219
236
|
# This method was defined manually
|
220
237
|
end
|
221
238
|
else
|
222
|
-
raise "Can't
|
239
|
+
raise "Can't generate_initialize because scalar_methods wasn't called; call it before children_methods"
|
223
240
|
end
|
224
241
|
end
|
225
242
|
|
@@ -248,7 +265,17 @@ module GraphQL
|
|
248
265
|
end
|
249
266
|
end
|
250
267
|
|
251
|
-
|
268
|
+
DEFAULT_INITIALIZE_OPTIONS = [
|
269
|
+
"line: nil",
|
270
|
+
"col: nil",
|
271
|
+
"pos: nil",
|
272
|
+
"filename: nil",
|
273
|
+
"source: nil",
|
274
|
+
]
|
275
|
+
|
276
|
+
def generate_initialize
|
277
|
+
return if method_defined?(:marshal_load, false) # checking for `:initialize` doesn't work right
|
278
|
+
|
252
279
|
scalar_method_names = @scalar_methods
|
253
280
|
# TODO: These probably should be scalar methods, but `types` returns an array
|
254
281
|
[:types, :description].each do |extra_method|
|
@@ -257,22 +284,54 @@ module GraphQL
|
|
257
284
|
end
|
258
285
|
end
|
259
286
|
|
260
|
-
|
287
|
+
children_method_names = @children_methods.keys
|
288
|
+
|
289
|
+
all_method_names = scalar_method_names + children_method_names
|
261
290
|
if all_method_names.include?(:alias)
|
262
291
|
# Rather than complicating this special case,
|
263
292
|
# let it be overridden (in field)
|
264
293
|
return
|
265
294
|
else
|
266
295
|
arguments = scalar_method_names.map { |m| "#{m}: nil"} +
|
267
|
-
|
296
|
+
children_method_names.map { |m| "#{m}: NO_CHILDREN" } +
|
297
|
+
DEFAULT_INITIALIZE_OPTIONS
|
268
298
|
|
269
299
|
assignments = scalar_method_names.map { |m| "@#{m} = #{m}"} +
|
270
|
-
|
300
|
+
children_method_names.map { |m| "@#{m} = #{m}.freeze" }
|
301
|
+
|
302
|
+
if name.end_with?("Definition") && name != "FragmentDefinition"
|
303
|
+
arguments << "definition_pos: nil"
|
304
|
+
assignments << "@definition_pos = definition_pos"
|
305
|
+
end
|
306
|
+
|
307
|
+
keywords = scalar_method_names.map { |m| "#{m}: #{m}"} +
|
308
|
+
children_method_names.map { |m| "#{m}: #{m}" }
|
271
309
|
|
272
310
|
module_eval <<-RUBY, __FILE__, __LINE__
|
273
|
-
def
|
311
|
+
def initialize(#{arguments.join(", ")})
|
312
|
+
@line = line
|
313
|
+
@col = col
|
314
|
+
@pos = pos
|
315
|
+
@filename = filename
|
316
|
+
@source = source
|
274
317
|
#{assignments.join("\n")}
|
275
318
|
end
|
319
|
+
|
320
|
+
def self.from_a(filename, line, col, #{all_method_names.join(", ")})
|
321
|
+
self.new(filename: filename, line: line, col: col, #{keywords.join(", ")})
|
322
|
+
end
|
323
|
+
|
324
|
+
def marshal_dump
|
325
|
+
[
|
326
|
+
line, col, # use methods here to force them to be calculated
|
327
|
+
@filename,
|
328
|
+
#{all_method_names.map { |n| "@#{n}," }.join}
|
329
|
+
]
|
330
|
+
end
|
331
|
+
|
332
|
+
def marshal_load(values)
|
333
|
+
@line, @col, @filename #{all_method_names.map { |n| ", @#{n}"}.join} = values
|
334
|
+
end
|
276
335
|
RUBY
|
277
336
|
end
|
278
337
|
end
|
@@ -300,10 +359,10 @@ module GraphQL
|
|
300
359
|
# @return [String] the key for this argument
|
301
360
|
|
302
361
|
# @!attribute value
|
303
|
-
# @return [String, Float, Integer, Boolean, Array, InputObject] The value passed for this key
|
362
|
+
# @return [String, Float, Integer, Boolean, Array, InputObject, VariableIdentifier] The value passed for this key
|
304
363
|
|
305
364
|
def children
|
306
|
-
@children ||= Array(value).flatten.select { |v| v.is_a?(AbstractNode) }
|
365
|
+
@children ||= Array(value).flatten.tap { _1.select! { |v| v.is_a?(AbstractNode) } }
|
307
366
|
end
|
308
367
|
end
|
309
368
|
|
@@ -316,42 +375,13 @@ module GraphQL
|
|
316
375
|
end
|
317
376
|
|
318
377
|
class DirectiveDefinition < AbstractNode
|
319
|
-
include DefinitionNode
|
320
378
|
attr_reader :description
|
321
379
|
scalar_methods :name, :repeatable
|
322
380
|
children_methods(
|
323
|
-
locations: Nodes::DirectiveLocation,
|
324
381
|
arguments: Nodes::Argument,
|
382
|
+
locations: Nodes::DirectiveLocation,
|
325
383
|
)
|
326
|
-
|
327
|
-
|
328
|
-
# This is the AST root for normal queries
|
329
|
-
#
|
330
|
-
# @example Deriving a document by parsing a string
|
331
|
-
# document = GraphQL.parse(query_string)
|
332
|
-
#
|
333
|
-
# @example Creating a string from a document
|
334
|
-
# document.to_query_string
|
335
|
-
# # { ... }
|
336
|
-
#
|
337
|
-
# @example Creating a custom string from a document
|
338
|
-
# class VariableScrubber < GraphQL::Language::Printer
|
339
|
-
# def print_argument(arg)
|
340
|
-
# "#{arg.name}: <HIDDEN>"
|
341
|
-
# end
|
342
|
-
# end
|
343
|
-
#
|
344
|
-
# document.to_query_string(printer: VariableScrubber.new)
|
345
|
-
#
|
346
|
-
class Document < AbstractNode
|
347
|
-
scalar_methods false
|
348
|
-
children_methods(definitions: nil)
|
349
|
-
# @!attribute definitions
|
350
|
-
# @return [Array<OperationDefinition, FragmentDefinition>] top-level GraphQL units: operations or fragments
|
351
|
-
|
352
|
-
def slice_definition(name)
|
353
|
-
GraphQL::Language::DefinitionSlice.slice(self, name)
|
354
|
-
end
|
384
|
+
self.children_method_name = :definitions
|
355
385
|
end
|
356
386
|
|
357
387
|
# An enum value. The string is available as {#name}.
|
@@ -364,7 +394,31 @@ module GraphQL
|
|
364
394
|
|
365
395
|
# A single selection in a GraphQL query.
|
366
396
|
class Field < AbstractNode
|
367
|
-
NONE
|
397
|
+
def initialize(name: nil, arguments: NONE, directives: NONE, selections: NONE, field_alias: nil, line: nil, col: nil, pos: nil, filename: nil, source: nil)
|
398
|
+
@name = name
|
399
|
+
@arguments = arguments || NONE
|
400
|
+
@directives = directives || NONE
|
401
|
+
@selections = selections || NONE
|
402
|
+
# oops, alias is a keyword:
|
403
|
+
@alias = field_alias
|
404
|
+
@line = line
|
405
|
+
@col = col
|
406
|
+
@pos = pos
|
407
|
+
@filename = filename
|
408
|
+
@source = source
|
409
|
+
end
|
410
|
+
|
411
|
+
def self.from_a(filename, line, col, field_alias, name, arguments, directives, selections) # rubocop:disable Metrics/ParameterLists
|
412
|
+
self.new(filename: filename, line: line, col: col, field_alias: field_alias, name: name, arguments: arguments, directives: directives, selections: selections)
|
413
|
+
end
|
414
|
+
|
415
|
+
def marshal_dump
|
416
|
+
[line, col, @filename, @name, @arguments, @directives, @selections, @alias]
|
417
|
+
end
|
418
|
+
|
419
|
+
def marshal_load(values)
|
420
|
+
@line, @col, @filename, @name, @arguments, @directives, @selections, @alias = values
|
421
|
+
end
|
368
422
|
|
369
423
|
scalar_methods :name, :alias
|
370
424
|
children_methods({
|
@@ -373,34 +427,34 @@ module GraphQL
|
|
373
427
|
directives: GraphQL::Language::Nodes::Directive,
|
374
428
|
})
|
375
429
|
|
376
|
-
# @!attribute selections
|
377
|
-
# @return [Array<Nodes::Field>] Selections on this object (or empty array if this is a scalar field)
|
378
|
-
|
379
|
-
def initialize_node(attributes)
|
380
|
-
@name = attributes[:name]
|
381
|
-
@arguments = attributes[:arguments] || NONE
|
382
|
-
@directives = attributes[:directives] || NONE
|
383
|
-
@selections = attributes[:selections] || NONE
|
384
|
-
# oops, alias is a keyword:
|
385
|
-
@alias = attributes[:alias]
|
386
|
-
end
|
387
|
-
|
388
430
|
# Override this because default is `:fields`
|
389
431
|
self.children_method_name = :selections
|
390
432
|
end
|
391
433
|
|
392
434
|
# A reusable fragment, defined at document-level.
|
393
435
|
class FragmentDefinition < AbstractNode
|
394
|
-
|
395
|
-
# @return [String] the identifier for this fragment, which may be applied with `...#{name}`
|
396
|
-
|
397
|
-
# @!attribute type
|
398
|
-
# @return [String] the type condition for this fragment (name of type which it may apply to)
|
399
|
-
def initialize_node(name: nil, type: nil, directives: [], selections: [])
|
436
|
+
def initialize(name: nil, type: nil, directives: NONE, selections: NONE, filename: nil, pos: nil, source: nil, line: nil, col: nil)
|
400
437
|
@name = name
|
401
438
|
@type = type
|
402
439
|
@directives = directives
|
403
440
|
@selections = selections
|
441
|
+
@filename = filename
|
442
|
+
@pos = pos
|
443
|
+
@source = source
|
444
|
+
@line = line
|
445
|
+
@col = col
|
446
|
+
end
|
447
|
+
|
448
|
+
def self.from_a(filename, line, col, name, type, directives, selections)
|
449
|
+
self.new(filename: filename, line: line, col: col, name: name, type: type, directives: directives, selections: selections)
|
450
|
+
end
|
451
|
+
|
452
|
+
def marshal_dump
|
453
|
+
[line, col, @filename, @name, @type, @directives, @selections]
|
454
|
+
end
|
455
|
+
|
456
|
+
def marshal_load(values)
|
457
|
+
@line, @col, @filename, @name, @type, @directives, @selections = values
|
404
458
|
end
|
405
459
|
|
406
460
|
scalar_methods :name, :type
|
@@ -427,8 +481,8 @@ module GraphQL
|
|
427
481
|
class InlineFragment < AbstractNode
|
428
482
|
scalar_methods :type
|
429
483
|
children_methods({
|
430
|
-
selections: GraphQL::Language::Nodes::Field,
|
431
484
|
directives: GraphQL::Language::Nodes::Directive,
|
485
|
+
selections: GraphQL::Language::Nodes::Field,
|
432
486
|
})
|
433
487
|
|
434
488
|
self.children_method_name = :selections
|
@@ -487,7 +541,7 @@ module GraphQL
|
|
487
541
|
# An operation-level query variable
|
488
542
|
class VariableDefinition < AbstractNode
|
489
543
|
scalar_methods :name, :type, :default_value
|
490
|
-
children_methods
|
544
|
+
children_methods(directives: Directive)
|
491
545
|
# @!attribute default_value
|
492
546
|
# @return [String, Integer, Float, Boolean, Array, NullValue] A Ruby value to use if no other value is provided
|
493
547
|
|
@@ -507,8 +561,8 @@ module GraphQL
|
|
507
561
|
scalar_methods :operation_type, :name
|
508
562
|
children_methods({
|
509
563
|
variables: GraphQL::Language::Nodes::VariableDefinition,
|
510
|
-
selections: GraphQL::Language::Nodes::Field,
|
511
564
|
directives: GraphQL::Language::Nodes::Directive,
|
565
|
+
selections: GraphQL::Language::Nodes::Field,
|
512
566
|
})
|
513
567
|
|
514
568
|
# @!attribute variables
|
@@ -526,6 +580,35 @@ module GraphQL
|
|
526
580
|
self.children_method_name = :definitions
|
527
581
|
end
|
528
582
|
|
583
|
+
# This is the AST root for normal queries
|
584
|
+
#
|
585
|
+
# @example Deriving a document by parsing a string
|
586
|
+
# document = GraphQL.parse(query_string)
|
587
|
+
#
|
588
|
+
# @example Creating a string from a document
|
589
|
+
# document.to_query_string
|
590
|
+
# # { ... }
|
591
|
+
#
|
592
|
+
# @example Creating a custom string from a document
|
593
|
+
# class VariableScrubber < GraphQL::Language::Printer
|
594
|
+
# def print_argument(arg)
|
595
|
+
# print_string("#{arg.name}: <HIDDEN>")
|
596
|
+
# end
|
597
|
+
# end
|
598
|
+
#
|
599
|
+
# document.to_query_string(printer: VariableScrubber.new)
|
600
|
+
#
|
601
|
+
class Document < AbstractNode
|
602
|
+
scalar_methods false
|
603
|
+
children_methods(definitions: nil)
|
604
|
+
# @!attribute definitions
|
605
|
+
# @return [Array<OperationDefinition, FragmentDefinition>] top-level GraphQL units: operations or fragments
|
606
|
+
|
607
|
+
def slice_definition(name)
|
608
|
+
GraphQL::Language::DefinitionSlice.slice(self, name)
|
609
|
+
end
|
610
|
+
end
|
611
|
+
|
529
612
|
# A type name, used for variable definitions
|
530
613
|
class TypeName < NameOnlyNode
|
531
614
|
end
|
@@ -536,7 +619,6 @@ module GraphQL
|
|
536
619
|
end
|
537
620
|
|
538
621
|
class SchemaDefinition < AbstractNode
|
539
|
-
include DefinitionNode
|
540
622
|
scalar_methods :query, :mutation, :subscription
|
541
623
|
children_methods({
|
542
624
|
directives: GraphQL::Language::Nodes::Directive,
|
@@ -553,7 +635,6 @@ module GraphQL
|
|
553
635
|
end
|
554
636
|
|
555
637
|
class ScalarTypeDefinition < AbstractNode
|
556
|
-
include DefinitionNode
|
557
638
|
attr_reader :description
|
558
639
|
scalar_methods :name
|
559
640
|
children_methods({
|
@@ -571,7 +652,6 @@ module GraphQL
|
|
571
652
|
end
|
572
653
|
|
573
654
|
class InputValueDefinition < AbstractNode
|
574
|
-
include DefinitionNode
|
575
655
|
attr_reader :description
|
576
656
|
scalar_methods :name, :type, :default_value
|
577
657
|
children_methods({
|
@@ -581,12 +661,11 @@ module GraphQL
|
|
581
661
|
end
|
582
662
|
|
583
663
|
class FieldDefinition < AbstractNode
|
584
|
-
include DefinitionNode
|
585
664
|
attr_reader :description
|
586
665
|
scalar_methods :name, :type
|
587
666
|
children_methods({
|
588
|
-
directives: GraphQL::Language::Nodes::Directive,
|
589
667
|
arguments: GraphQL::Language::Nodes::InputValueDefinition,
|
668
|
+
directives: GraphQL::Language::Nodes::Directive,
|
590
669
|
})
|
591
670
|
self.children_method_name = :fields
|
592
671
|
|
@@ -602,7 +681,6 @@ module GraphQL
|
|
602
681
|
end
|
603
682
|
|
604
683
|
class ObjectTypeDefinition < AbstractNode
|
605
|
-
include DefinitionNode
|
606
684
|
attr_reader :description
|
607
685
|
scalar_methods :name, :interfaces
|
608
686
|
children_methods({
|
@@ -622,7 +700,6 @@ module GraphQL
|
|
622
700
|
end
|
623
701
|
|
624
702
|
class InterfaceTypeDefinition < AbstractNode
|
625
|
-
include DefinitionNode
|
626
703
|
attr_reader :description
|
627
704
|
scalar_methods :name
|
628
705
|
children_methods({
|
@@ -644,7 +721,6 @@ module GraphQL
|
|
644
721
|
end
|
645
722
|
|
646
723
|
class UnionTypeDefinition < AbstractNode
|
647
|
-
include DefinitionNode
|
648
724
|
attr_reader :description, :types
|
649
725
|
scalar_methods :name
|
650
726
|
children_methods({
|
@@ -663,7 +739,6 @@ module GraphQL
|
|
663
739
|
end
|
664
740
|
|
665
741
|
class EnumValueDefinition < AbstractNode
|
666
|
-
include DefinitionNode
|
667
742
|
attr_reader :description
|
668
743
|
scalar_methods :name
|
669
744
|
children_methods({
|
@@ -673,7 +748,6 @@ module GraphQL
|
|
673
748
|
end
|
674
749
|
|
675
750
|
class EnumTypeDefinition < AbstractNode
|
676
|
-
include DefinitionNode
|
677
751
|
attr_reader :description
|
678
752
|
scalar_methods :name
|
679
753
|
children_methods({
|
@@ -693,7 +767,6 @@ module GraphQL
|
|
693
767
|
end
|
694
768
|
|
695
769
|
class InputObjectTypeDefinition < AbstractNode
|
696
|
-
include DefinitionNode
|
697
770
|
attr_reader :description
|
698
771
|
scalar_methods :name
|
699
772
|
children_methods({
|