graphql 1.13.24 → 2.0.0
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 +4 -4
- data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
- data/lib/graphql/analysis/ast/query_depth.rb +0 -1
- data/lib/graphql/analysis/ast/visitor.rb +1 -1
- data/lib/graphql/analysis/ast.rb +0 -10
- data/lib/graphql/analysis.rb +0 -7
- data/lib/graphql/backtrace/table.rb +0 -18
- data/lib/graphql/backtrace/tracer.rb +1 -2
- data/lib/graphql/backtrace.rb +2 -8
- data/lib/graphql/dig.rb +1 -1
- data/lib/graphql/execution/errors.rb +1 -9
- data/lib/graphql/execution/interpreter/runtime.rb +6 -13
- data/lib/graphql/execution/interpreter.rb +0 -22
- data/lib/graphql/execution/lazy.rb +1 -1
- data/lib/graphql/execution/lookahead.rb +6 -13
- data/lib/graphql/execution/multiplex.rb +50 -107
- data/lib/graphql/execution.rb +11 -3
- data/lib/graphql/introspection/directive_type.rb +2 -2
- data/lib/graphql/introspection/dynamic_fields.rb +3 -8
- data/lib/graphql/introspection/entry_points.rb +2 -15
- data/lib/graphql/introspection/field_type.rb +1 -1
- data/lib/graphql/introspection/schema_type.rb +2 -2
- data/lib/graphql/introspection/type_type.rb +5 -5
- data/lib/graphql/language/document_from_schema_definition.rb +0 -17
- data/lib/graphql/language/nodes.rb +0 -3
- data/lib/graphql/pagination/connections.rb +2 -28
- data/lib/graphql/query/context.rb +1 -185
- data/lib/graphql/query/input_validation_result.rb +0 -9
- data/lib/graphql/query/literal_input.rb +8 -13
- data/lib/graphql/query/validation_pipeline.rb +6 -34
- data/lib/graphql/query/variable_validation_error.rb +2 -2
- data/lib/graphql/query/variables.rb +8 -31
- data/lib/graphql/query.rb +5 -34
- data/lib/graphql/railtie.rb +0 -104
- data/lib/graphql/relay/range_add.rb +0 -4
- data/lib/graphql/relay.rb +0 -15
- data/lib/graphql/schema/addition.rb +1 -8
- data/lib/graphql/schema/argument.rb +6 -28
- data/lib/graphql/schema/build_from_definition.rb +7 -9
- data/lib/graphql/schema/directive.rb +1 -22
- data/lib/graphql/schema/enum.rb +3 -19
- data/lib/graphql/schema/enum_value.rb +1 -23
- data/lib/graphql/schema/field.rb +22 -221
- data/lib/graphql/schema/input_object.rb +17 -65
- data/lib/graphql/schema/interface.rb +1 -30
- data/lib/graphql/schema/introspection_system.rb +3 -8
- data/lib/graphql/schema/late_bound_type.rb +2 -2
- data/lib/graphql/schema/list.rb +3 -24
- data/lib/graphql/schema/loader.rb +0 -1
- data/lib/graphql/schema/member/base_dsl_methods.rb +1 -6
- data/lib/graphql/schema/member/build_type.rb +4 -6
- data/lib/graphql/schema/member/has_arguments.rb +16 -20
- data/lib/graphql/schema/member/has_fields.rb +3 -3
- data/lib/graphql/schema/member/has_interfaces.rb +1 -13
- data/lib/graphql/schema/member/validates_input.rb +2 -2
- data/lib/graphql/schema/member.rb +0 -6
- data/lib/graphql/schema/mutation.rb +0 -9
- data/lib/graphql/schema/non_null.rb +3 -9
- data/lib/graphql/schema/object.rb +0 -40
- data/lib/graphql/schema/relay_classic_mutation.rb +17 -28
- data/lib/graphql/schema/scalar.rb +1 -16
- data/lib/graphql/schema/union.rb +0 -16
- data/lib/graphql/schema/warden.rb +3 -12
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +106 -945
- data/lib/graphql/static_validation/base_visitor.rb +4 -21
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
- data/lib/graphql/static_validation/validator.rb +2 -24
- data/lib/graphql/static_validation.rb +0 -2
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
- data/lib/graphql/subscriptions/event.rb +1 -1
- data/lib/graphql/subscriptions/instrumentation.rb +0 -51
- data/lib/graphql/subscriptions.rb +4 -13
- data/lib/graphql/tracing/data_dog_tracing.rb +16 -20
- data/lib/graphql/tracing/platform_tracing.rb +4 -32
- data/lib/graphql/tracing.rb +0 -1
- data/lib/graphql/types/relay/connection_behaviors.rb +2 -6
- data/lib/graphql/types/relay/default_relay.rb +0 -10
- data/lib/graphql/types/relay/node_behaviors.rb +5 -1
- data/lib/graphql/types/relay.rb +0 -2
- data/lib/graphql/types/string.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +1 -66
- metadata +28 -164
- data/lib/graphql/analysis/analyze_query.rb +0 -98
- data/lib/graphql/analysis/field_usage.rb +0 -45
- data/lib/graphql/analysis/max_query_complexity.rb +0 -26
- data/lib/graphql/analysis/max_query_depth.rb +0 -26
- data/lib/graphql/analysis/query_complexity.rb +0 -88
- data/lib/graphql/analysis/query_depth.rb +0 -43
- data/lib/graphql/analysis/reducer_state.rb +0 -48
- data/lib/graphql/argument.rb +0 -131
- data/lib/graphql/authorization.rb +0 -82
- data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
- data/lib/graphql/backwards_compatibility.rb +0 -61
- data/lib/graphql/base_type.rb +0 -232
- data/lib/graphql/boolean_type.rb +0 -2
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
- data/lib/graphql/compatibility/execution_specification.rb +0 -436
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
- data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
- data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
- data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
- data/lib/graphql/compatibility.rb +0 -5
- data/lib/graphql/define/assign_argument.rb +0 -12
- data/lib/graphql/define/assign_connection.rb +0 -13
- data/lib/graphql/define/assign_enum_value.rb +0 -18
- data/lib/graphql/define/assign_global_id_field.rb +0 -11
- data/lib/graphql/define/assign_mutation_function.rb +0 -34
- data/lib/graphql/define/assign_object_field.rb +0 -42
- data/lib/graphql/define/defined_object_proxy.rb +0 -53
- data/lib/graphql/define/instance_definable.rb +0 -255
- data/lib/graphql/define/no_definition_error.rb +0 -7
- data/lib/graphql/define/non_null_with_bang.rb +0 -16
- data/lib/graphql/define/type_definer.rb +0 -31
- data/lib/graphql/define.rb +0 -31
- data/lib/graphql/deprecated_dsl.rb +0 -55
- data/lib/graphql/directive/deprecated_directive.rb +0 -2
- data/lib/graphql/directive/include_directive.rb +0 -2
- data/lib/graphql/directive/skip_directive.rb +0 -2
- data/lib/graphql/directive.rb +0 -107
- data/lib/graphql/enum_type.rb +0 -133
- data/lib/graphql/execution/execute.rb +0 -333
- data/lib/graphql/execution/flatten.rb +0 -40
- data/lib/graphql/execution/typecast.rb +0 -50
- data/lib/graphql/field/resolve.rb +0 -59
- data/lib/graphql/field.rb +0 -226
- data/lib/graphql/float_type.rb +0 -2
- data/lib/graphql/function.rb +0 -128
- data/lib/graphql/id_type.rb +0 -2
- data/lib/graphql/input_object_type.rb +0 -138
- data/lib/graphql/int_type.rb +0 -2
- data/lib/graphql/interface_type.rb +0 -72
- data/lib/graphql/internal_representation/document.rb +0 -27
- data/lib/graphql/internal_representation/node.rb +0 -206
- data/lib/graphql/internal_representation/print.rb +0 -51
- data/lib/graphql/internal_representation/rewrite.rb +0 -184
- data/lib/graphql/internal_representation/scope.rb +0 -88
- data/lib/graphql/internal_representation/visit.rb +0 -36
- data/lib/graphql/internal_representation.rb +0 -7
- data/lib/graphql/list_type.rb +0 -80
- data/lib/graphql/non_null_type.rb +0 -71
- data/lib/graphql/object_type.rb +0 -130
- data/lib/graphql/query/arguments.rb +0 -189
- data/lib/graphql/query/arguments_cache.rb +0 -24
- data/lib/graphql/query/executor.rb +0 -52
- data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
- data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
- data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
- data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
- data/lib/graphql/query/serial_execution.rb +0 -40
- data/lib/graphql/relay/array_connection.rb +0 -83
- data/lib/graphql/relay/base_connection.rb +0 -189
- data/lib/graphql/relay/connection_instrumentation.rb +0 -54
- data/lib/graphql/relay/connection_resolve.rb +0 -43
- data/lib/graphql/relay/connection_type.rb +0 -54
- data/lib/graphql/relay/edge.rb +0 -27
- data/lib/graphql/relay/edge_type.rb +0 -19
- data/lib/graphql/relay/edges_instrumentation.rb +0 -39
- data/lib/graphql/relay/global_id_resolve.rb +0 -17
- data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
- data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
- data/lib/graphql/relay/mutation/resolve.rb +0 -56
- data/lib/graphql/relay/mutation/result.rb +0 -38
- data/lib/graphql/relay/mutation.rb +0 -106
- data/lib/graphql/relay/node.rb +0 -39
- data/lib/graphql/relay/page_info.rb +0 -7
- data/lib/graphql/relay/relation_connection.rb +0 -188
- data/lib/graphql/relay/type_extensions.rb +0 -32
- data/lib/graphql/scalar_type.rb +0 -91
- data/lib/graphql/schema/catchall_middleware.rb +0 -35
- data/lib/graphql/schema/default_parse_error.rb +0 -10
- data/lib/graphql/schema/default_type_error.rb +0 -17
- data/lib/graphql/schema/member/accepts_definition.rb +0 -164
- data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
- data/lib/graphql/schema/member/instrumentation.rb +0 -131
- data/lib/graphql/schema/middleware_chain.rb +0 -82
- data/lib/graphql/schema/possible_types.rb +0 -44
- data/lib/graphql/schema/rescue_middleware.rb +0 -60
- data/lib/graphql/schema/timeout_middleware.rb +0 -88
- data/lib/graphql/schema/traversal.rb +0 -228
- data/lib/graphql/schema/validation.rb +0 -313
- data/lib/graphql/static_validation/default_visitor.rb +0 -15
- data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
- data/lib/graphql/string_type.rb +0 -2
- data/lib/graphql/subscriptions/subscription_root.rb +0 -76
- data/lib/graphql/tracing/skylight_tracing.rb +0 -70
- data/lib/graphql/types/relay/node_field.rb +0 -24
- data/lib/graphql/types/relay/nodes_field.rb +0 -43
- data/lib/graphql/union_type.rb +0 -115
- data/lib/graphql/upgrader/member.rb +0 -937
- data/lib/graphql/upgrader/schema.rb +0 -38
data/lib/graphql/schema/field.rb
CHANGED
@@ -5,8 +5,6 @@ require "graphql/schema/field/scope_extension"
|
|
5
5
|
module GraphQL
|
6
6
|
class Schema
|
7
7
|
class Field
|
8
|
-
include GraphQL::Schema::Member::CachedGraphQLDefinition
|
9
|
-
include GraphQL::Schema::Member::AcceptsDefinition
|
10
8
|
include GraphQL::Schema::Member::HasArguments
|
11
9
|
include GraphQL::Schema::Member::HasAstNode
|
12
10
|
include GraphQL::Schema::Member::HasPath
|
@@ -84,16 +82,6 @@ module GraphQL
|
|
84
82
|
# @return [GraphQL::Schema:Field] an instance of `self
|
85
83
|
# @see {.initialize} for other options
|
86
84
|
def self.from_options(name = nil, type = nil, desc = nil, resolver: nil, mutation: nil, subscription: nil,**kwargs, &block)
|
87
|
-
if kwargs[:field]
|
88
|
-
if kwargs[:field].is_a?(GraphQL::Field) && kwargs[:field] == GraphQL::Types::Relay::NodeField.graphql_definition
|
89
|
-
GraphQL::Deprecation.warn("Legacy-style `GraphQL::Relay::Node.field` is being added to a class-based type. See `GraphQL::Types::Relay::NodeField` for a replacement.")
|
90
|
-
return GraphQL::Types::Relay::NodeField
|
91
|
-
elsif kwargs[:field].is_a?(GraphQL::Field) && kwargs[:field] == GraphQL::Types::Relay::NodesField.graphql_definition
|
92
|
-
GraphQL::Deprecation.warn("Legacy-style `GraphQL::Relay::Node.plural_field` is being added to a class-based type. See `GraphQL::Types::Relay::NodesField` for a replacement.")
|
93
|
-
return GraphQL::Types::Relay::NodesField
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
85
|
if (parent_config = resolver || mutation || subscription)
|
98
86
|
# Get the parent config, merge in local overrides
|
99
87
|
kwargs = parent_config.field_options.merge(kwargs)
|
@@ -106,9 +94,6 @@ module GraphQL
|
|
106
94
|
end
|
107
95
|
|
108
96
|
if !type.nil?
|
109
|
-
if type.is_a?(GraphQL::Field)
|
110
|
-
raise ArgumentError, "A GraphQL::Field was passed as the second argument, use the `field:` keyword for this instead."
|
111
|
-
end
|
112
97
|
if desc
|
113
98
|
if kwargs[:description]
|
114
99
|
raise ArgumentError, "Provide description as a positional argument or `description:` keyword, but not both (#{desc.inspect}, #{kwargs[:description].inspect})"
|
@@ -176,8 +161,6 @@ module GraphQL
|
|
176
161
|
|
177
162
|
# @return Boolean
|
178
163
|
attr_reader :relay_node_field
|
179
|
-
# @return Boolean
|
180
|
-
attr_reader :relay_nodes_field
|
181
164
|
|
182
165
|
# @return [Boolean] Should we warn if this field's name conflicts with a built-in method?
|
183
166
|
def method_conflict_warning?
|
@@ -214,8 +197,7 @@ module GraphQL
|
|
214
197
|
# @param ast_node [Language::Nodes::FieldDefinition, nil] If this schema was parsed from definition, this AST node defined the field
|
215
198
|
# @param method_conflict_warning [Boolean] If false, skip the warning if this field's method conflicts with a built-in method
|
216
199
|
# @param validates [Array<Hash>] Configurations for validating this field
|
217
|
-
|
218
|
-
def initialize(type: nil, name: nil, owner: nil, null: true, field: nil, function: nil, description: nil, deprecation_reason: nil, method: nil, hash_key: nil, dig: nil, resolver_method: nil, resolve: nil, connection: nil, max_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: 1, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, legacy_edge_class: nil, &definition_block)
|
200
|
+
def initialize(type: nil, name: nil, owner: nil, null: true, field: nil, function: nil, description: nil, deprecation_reason: nil, method: nil, hash_key: nil, dig: nil, resolver_method: nil, resolve: nil, connection: nil, max_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: 1, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, &definition_block)
|
219
201
|
if name.nil?
|
220
202
|
raise ArgumentError, "missing first `name` argument or keyword `name:`"
|
221
203
|
end
|
@@ -229,10 +211,8 @@ module GraphQL
|
|
229
211
|
end
|
230
212
|
@original_name = name
|
231
213
|
name_s = -name.to_s
|
232
|
-
|
233
214
|
@underscored_name = -Member::BuildType.underscore(name_s)
|
234
215
|
@name = -(camelize ? Member::BuildType.camelize(name_s) : name_s)
|
235
|
-
NameValidator.validate!(@name)
|
236
216
|
@description = description
|
237
217
|
if field.is_a?(GraphQL::Schema::Field)
|
238
218
|
raise ArgumentError, "Instead of passing a field as `field:`, use `add_field(field)` to add an already-defined field."
|
@@ -260,10 +240,6 @@ module GraphQL
|
|
260
240
|
# TODO: I think non-string/symbol hash keys are wrongly normalized (eg `1` will not work)
|
261
241
|
method_name = method || hash_key || name_s
|
262
242
|
@dig_keys = dig
|
263
|
-
if hash_key
|
264
|
-
@hash_key = hash_key
|
265
|
-
end
|
266
|
-
|
267
243
|
resolver_method ||= name_s.to_sym
|
268
244
|
|
269
245
|
@method_str = -method_name.to_s
|
@@ -285,7 +261,6 @@ module GraphQL
|
|
285
261
|
@relay_nodes_field = relay_nodes_field
|
286
262
|
@ast_node = ast_node
|
287
263
|
@method_conflict_warning = method_conflict_warning
|
288
|
-
@legacy_edge_class = legacy_edge_class
|
289
264
|
|
290
265
|
arguments.each do |name, arg|
|
291
266
|
case arg
|
@@ -479,13 +454,7 @@ module GraphQL
|
|
479
454
|
case defined_complexity
|
480
455
|
when Proc
|
481
456
|
arguments = query.arguments_for(nodes.first, self)
|
482
|
-
|
483
|
-
return child_complexity
|
484
|
-
elsif arguments.respond_to?(:keyword_arguments)
|
485
|
-
arguments = arguments.keyword_arguments
|
486
|
-
end
|
487
|
-
|
488
|
-
defined_complexity.call(query.context, arguments, child_complexity)
|
457
|
+
defined_complexity.call(query.context, arguments.keyword_arguments, child_complexity)
|
489
458
|
when Numeric
|
490
459
|
defined_complexity + child_complexity
|
491
460
|
else
|
@@ -522,82 +491,6 @@ module GraphQL
|
|
522
491
|
# @return [Integer, nil] Applied to connections if {#has_max_page_size?}
|
523
492
|
attr_reader :max_page_size
|
524
493
|
|
525
|
-
prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
|
526
|
-
|
527
|
-
# @return [GraphQL::Field]
|
528
|
-
def to_graphql
|
529
|
-
field_defn = if @field
|
530
|
-
@field.dup
|
531
|
-
elsif @function
|
532
|
-
GraphQL::Function.build_field(@function)
|
533
|
-
else
|
534
|
-
GraphQL::Field.new
|
535
|
-
end
|
536
|
-
|
537
|
-
field_defn.name = @name
|
538
|
-
if @return_type_expr
|
539
|
-
field_defn.type = -> { type }
|
540
|
-
end
|
541
|
-
|
542
|
-
if @description
|
543
|
-
field_defn.description = @description
|
544
|
-
end
|
545
|
-
|
546
|
-
if self.deprecation_reason
|
547
|
-
field_defn.deprecation_reason = self.deprecation_reason
|
548
|
-
end
|
549
|
-
|
550
|
-
if @resolver_class
|
551
|
-
if @resolver_class < GraphQL::Schema::Mutation
|
552
|
-
field_defn.mutation = @resolver_class
|
553
|
-
end
|
554
|
-
field_defn.metadata[:resolver] = @resolver_class
|
555
|
-
end
|
556
|
-
|
557
|
-
if !@trace.nil?
|
558
|
-
field_defn.trace = @trace
|
559
|
-
end
|
560
|
-
|
561
|
-
if @relay_node_field
|
562
|
-
field_defn.relay_node_field = @relay_node_field
|
563
|
-
end
|
564
|
-
|
565
|
-
if @relay_nodes_field
|
566
|
-
field_defn.relay_nodes_field = @relay_nodes_field
|
567
|
-
end
|
568
|
-
|
569
|
-
if @legacy_edge_class
|
570
|
-
field_defn.edge_class = @legacy_edge_class
|
571
|
-
end
|
572
|
-
|
573
|
-
field_defn.resolve = self.method(:resolve_field)
|
574
|
-
field_defn.connection = connection?
|
575
|
-
field_defn.connection_max_page_size = max_page_size
|
576
|
-
field_defn.introspection = @introspection
|
577
|
-
field_defn.complexity = @complexity
|
578
|
-
field_defn.subscription_scope = @subscription_scope
|
579
|
-
field_defn.ast_node = ast_node
|
580
|
-
|
581
|
-
all_argument_definitions.each do |defn|
|
582
|
-
arg_graphql = defn.deprecated_to_graphql
|
583
|
-
field_defn.arguments[arg_graphql.name] = arg_graphql # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
584
|
-
end
|
585
|
-
|
586
|
-
# Support a passed-in proc, one way or another
|
587
|
-
@resolve_proc = if @resolve
|
588
|
-
@resolve
|
589
|
-
elsif @function
|
590
|
-
@function
|
591
|
-
elsif @field
|
592
|
-
@field.resolve_proc
|
593
|
-
end
|
594
|
-
|
595
|
-
# Ok, `self` isn't a class, but this is for consistency with the classes
|
596
|
-
field_defn.metadata[:type_class] = self
|
597
|
-
field_defn.arguments_class = GraphQL::Query::Arguments.construct_arguments_class(field_defn)
|
598
|
-
field_defn
|
599
|
-
end
|
600
|
-
|
601
494
|
class MissingReturnTypeError < GraphQL::Error; end
|
602
495
|
attr_writer :type
|
603
496
|
|
@@ -652,64 +545,31 @@ module GraphQL
|
|
652
545
|
arg_values = args
|
653
546
|
using_arg_values = false
|
654
547
|
end
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
if
|
662
|
-
|
663
|
-
|
664
|
-
next
|
665
|
-
else
|
666
|
-
application_arg_value = arg_value.value
|
667
|
-
if application_arg_value.is_a?(GraphQL::Execution::Interpreter::Arguments)
|
668
|
-
application_arg_value.keyword_arguments
|
669
|
-
end
|
670
|
-
end
|
548
|
+
# Faster than `.any?`
|
549
|
+
arguments(context).each_value do |arg|
|
550
|
+
arg_key = arg.keyword
|
551
|
+
if arg_values.key?(arg_key)
|
552
|
+
arg_value = arg_values[arg_key]
|
553
|
+
if using_arg_values
|
554
|
+
if arg_value.default_used?
|
555
|
+
# pass -- no auth required for default used
|
556
|
+
next
|
671
557
|
else
|
672
|
-
application_arg_value = arg_value
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
return false
|
558
|
+
application_arg_value = arg_value.value
|
559
|
+
if application_arg_value.is_a?(GraphQL::Execution::Interpreter::Arguments)
|
560
|
+
application_arg_value.keyword_arguments
|
561
|
+
end
|
677
562
|
end
|
563
|
+
else
|
564
|
+
application_arg_value = arg_value
|
678
565
|
end
|
679
|
-
end
|
680
|
-
end
|
681
|
-
true
|
682
|
-
end
|
683
|
-
end
|
684
566
|
|
685
|
-
|
686
|
-
|
687
|
-
# Eventually, we might hook up field instances to execution in another way. TBD.
|
688
|
-
# @see #resolve for how the interpreter hooks up to it
|
689
|
-
def resolve_field(obj, args, ctx)
|
690
|
-
ctx.schema.after_lazy(obj) do |after_obj|
|
691
|
-
# First, apply auth ...
|
692
|
-
query_ctx = ctx.query.context
|
693
|
-
# Some legacy fields can have `nil` here, not exactly sure why.
|
694
|
-
# @see https://github.com/rmosolgo/graphql-ruby/issues/1990 before removing
|
695
|
-
inner_obj = after_obj && after_obj.object
|
696
|
-
ctx.schema.after_lazy(to_ruby_args(after_obj, args, ctx)) do |ruby_args|
|
697
|
-
if authorized?(inner_obj, ruby_args, query_ctx)
|
698
|
-
# Then if it passed, resolve the field
|
699
|
-
if @resolve_proc
|
700
|
-
# Might be nil, still want to call the func in that case
|
701
|
-
with_extensions(inner_obj, ruby_args, query_ctx) do |extended_obj, extended_args|
|
702
|
-
# Pass the GraphQL args here for compatibility:
|
703
|
-
@resolve_proc.call(extended_obj, args, ctx)
|
704
|
-
end
|
705
|
-
else
|
706
|
-
public_send_field(after_obj, ruby_args, query_ctx)
|
567
|
+
if !arg.authorized?(object, application_arg_value, context)
|
568
|
+
return false
|
707
569
|
end
|
708
|
-
else
|
709
|
-
err = GraphQL::UnauthorizedFieldError.new(object: inner_obj, type: obj.class, context: ctx, field: self)
|
710
|
-
query_ctx.schema.unauthorized_field(err)
|
711
570
|
end
|
712
571
|
end
|
572
|
+
true
|
713
573
|
end
|
714
574
|
end
|
715
575
|
|
@@ -745,7 +605,7 @@ module GraphQL
|
|
745
605
|
err
|
746
606
|
end
|
747
607
|
|
748
|
-
# @param ctx [GraphQL::Query::Context
|
608
|
+
# @param ctx [GraphQL::Query::Context]
|
749
609
|
def fetch_extra(extra_name, ctx)
|
750
610
|
if extra_name != :path && extra_name != :ast_node && respond_to?(extra_name)
|
751
611
|
self.public_send(extra_name)
|
@@ -758,63 +618,6 @@ module GraphQL
|
|
758
618
|
|
759
619
|
private
|
760
620
|
|
761
|
-
NO_ARGS = {}.freeze
|
762
|
-
|
763
|
-
# Convert a GraphQL arguments instance into a Ruby-style hash.
|
764
|
-
#
|
765
|
-
# @param obj [GraphQL::Schema::Object] The object where this field is being resolved
|
766
|
-
# @param graphql_args [GraphQL::Query::Arguments]
|
767
|
-
# @param field_ctx [GraphQL::Query::Context::FieldResolutionContext]
|
768
|
-
# @return [Hash<Symbol => Any>]
|
769
|
-
def to_ruby_args(obj, graphql_args, field_ctx)
|
770
|
-
if graphql_args.any? || @extras.any?
|
771
|
-
# Splat the GraphQL::Arguments to Ruby keyword arguments
|
772
|
-
ruby_kwargs = graphql_args.to_kwargs
|
773
|
-
maybe_lazies = []
|
774
|
-
# Apply any `prepare` methods. Not great code organization, can this go somewhere better?
|
775
|
-
arguments(field_ctx).each do |name, arg_defn|
|
776
|
-
ruby_kwargs_key = arg_defn.keyword
|
777
|
-
|
778
|
-
if ruby_kwargs.key?(ruby_kwargs_key)
|
779
|
-
loads = arg_defn.loads
|
780
|
-
value = ruby_kwargs[ruby_kwargs_key]
|
781
|
-
loaded_value = if loads && !arg_defn.from_resolver?
|
782
|
-
if arg_defn.type.list?
|
783
|
-
loaded_values = value.map { |val| load_application_object(arg_defn, loads, val, field_ctx.query.context) }
|
784
|
-
field_ctx.schema.after_any_lazies(loaded_values) { |result| result }
|
785
|
-
else
|
786
|
-
load_application_object(arg_defn, loads, value, field_ctx.query.context)
|
787
|
-
end
|
788
|
-
elsif arg_defn.type.list? && value.is_a?(Array)
|
789
|
-
field_ctx.schema.after_any_lazies(value, &:itself)
|
790
|
-
else
|
791
|
-
value
|
792
|
-
end
|
793
|
-
|
794
|
-
maybe_lazies << field_ctx.schema.after_lazy(loaded_value) do |loaded_value|
|
795
|
-
prepared_value = if arg_defn.prepare
|
796
|
-
arg_defn.prepare_value(obj, loaded_value)
|
797
|
-
else
|
798
|
-
loaded_value
|
799
|
-
end
|
800
|
-
|
801
|
-
ruby_kwargs[ruby_kwargs_key] = prepared_value
|
802
|
-
end
|
803
|
-
end
|
804
|
-
end
|
805
|
-
|
806
|
-
@extras.each do |extra_arg|
|
807
|
-
ruby_kwargs[extra_arg] = fetch_extra(extra_arg, field_ctx)
|
808
|
-
end
|
809
|
-
|
810
|
-
field_ctx.schema.after_any_lazies(maybe_lazies) do
|
811
|
-
ruby_kwargs
|
812
|
-
end
|
813
|
-
else
|
814
|
-
NO_ARGS
|
815
|
-
end
|
816
|
-
end
|
817
|
-
|
818
621
|
def public_send_field(unextended_obj, unextended_ruby_kwargs, query_ctx)
|
819
622
|
with_extensions(unextended_obj, unextended_ruby_kwargs, query_ctx) do |obj, ruby_kwargs|
|
820
623
|
begin
|
@@ -830,7 +633,7 @@ module GraphQL
|
|
830
633
|
# Find a way to resolve this field, checking:
|
831
634
|
#
|
832
635
|
# - A method on the type instance;
|
833
|
-
# - Hash keys, if the wrapped object is a hash
|
636
|
+
# - Hash keys, if the wrapped object is a hash;
|
834
637
|
# - A method on the wrapped object;
|
835
638
|
# - Or, raise not implemented.
|
836
639
|
#
|
@@ -852,8 +655,6 @@ module GraphQL
|
|
852
655
|
else
|
853
656
|
inner_object[@method_str]
|
854
657
|
end
|
855
|
-
elsif defined?(@hash_key) && obj.object.respond_to?(:[])
|
856
|
-
obj.object[@hash_key]
|
857
658
|
elsif obj.object.respond_to?(@method_sym)
|
858
659
|
method_to_call = @method_sym
|
859
660
|
method_receiver = obj.object
|
@@ -2,7 +2,6 @@
|
|
2
2
|
module GraphQL
|
3
3
|
class Schema
|
4
4
|
class InputObject < GraphQL::Schema::Member
|
5
|
-
extend GraphQL::Schema::Member::AcceptsDefinition
|
6
5
|
extend Forwardable
|
7
6
|
extend GraphQL::Schema::Member::HasArguments
|
8
7
|
extend GraphQL::Schema::Member::HasArguments::ArgumentObjectLoader
|
@@ -13,49 +12,28 @@ module GraphQL
|
|
13
12
|
|
14
13
|
# @return [GraphQL::Query::Context] The context for this query
|
15
14
|
attr_reader :context
|
16
|
-
# @return [GraphQL::
|
15
|
+
# @return [GraphQL::Execution::Interpereter::Arguments] The underlying arguments instance
|
17
16
|
attr_reader :arguments
|
18
17
|
|
19
18
|
# Ruby-like hash behaviors, read-only
|
20
19
|
def_delegators :@ruby_style_hash, :keys, :values, :each, :map, :any?, :empty?
|
21
20
|
|
22
|
-
def initialize(arguments
|
21
|
+
def initialize(arguments, ruby_kwargs:, context:, defaults_used:)
|
23
22
|
@context = context
|
24
|
-
|
25
|
-
|
26
|
-
@arguments = arguments
|
27
|
-
else
|
28
|
-
@arguments = self.class.arguments_class.new(arguments, context: context, defaults_used: defaults_used)
|
29
|
-
# Symbolized, underscored hash:
|
30
|
-
@ruby_style_hash = @arguments.to_kwargs
|
31
|
-
end
|
23
|
+
@ruby_style_hash = ruby_kwargs
|
24
|
+
@arguments = arguments
|
32
25
|
# Apply prepares, not great to have it duplicated here.
|
33
|
-
maybe_lazies = []
|
34
26
|
self.class.arguments(context).each_value do |arg_defn|
|
35
27
|
ruby_kwargs_key = arg_defn.keyword
|
36
|
-
|
37
28
|
if @ruby_style_hash.key?(ruby_kwargs_key)
|
38
|
-
loads = arg_defn.loads
|
39
|
-
# Resolvers do this loading themselves;
|
40
|
-
# With the interpreter, it's done during `coerce_arguments`
|
41
|
-
if loads && !arg_defn.from_resolver? && !context.interpreter?
|
42
|
-
value = @ruby_style_hash[ruby_kwargs_key]
|
43
|
-
loaded_value = arg_defn.load_and_authorize_value(self, value, context)
|
44
|
-
maybe_lazies << context.schema.after_lazy(loaded_value) do |loaded_value|
|
45
|
-
overwrite_argument(ruby_kwargs_key, loaded_value)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
29
|
# Weirdly, procs are applied during coercion, but not methods.
|
50
30
|
# Probably because these methods require a `self`.
|
51
|
-
if arg_defn.prepare.is_a?(Symbol) || context.nil?
|
31
|
+
if arg_defn.prepare.is_a?(Symbol) || context.nil?
|
52
32
|
prepared_value = arg_defn.prepare_value(self, @ruby_style_hash[ruby_kwargs_key])
|
53
33
|
overwrite_argument(ruby_kwargs_key, prepared_value)
|
54
34
|
end
|
55
35
|
end
|
56
36
|
end
|
57
|
-
|
58
|
-
@maybe_lazies = maybe_lazies
|
59
37
|
end
|
60
38
|
|
61
39
|
def to_h
|
@@ -68,12 +46,10 @@ module GraphQL
|
|
68
46
|
|
69
47
|
def prepare
|
70
48
|
if @context
|
71
|
-
@context
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
self
|
76
|
-
end
|
49
|
+
object = @context[:current_object]
|
50
|
+
# Pass this object's class with `as` so that messages are rendered correctly from inherited validators
|
51
|
+
Schema::Validator.validate!(self.class.validators, object, @context, @ruby_style_hash, as: self.class)
|
52
|
+
self
|
77
53
|
else
|
78
54
|
self
|
79
55
|
end
|
@@ -83,7 +59,6 @@ module GraphQL
|
|
83
59
|
# Authorize each argument (but this doesn't apply if `prepare` is implemented):
|
84
60
|
if value.respond_to?(:key?)
|
85
61
|
arguments(ctx).each do |_name, input_obj_arg|
|
86
|
-
input_obj_arg = input_obj_arg.type_class
|
87
62
|
if value.key?(input_obj_arg.keyword) &&
|
88
63
|
!input_obj_arg.authorized?(obj, value[input_obj_arg.keyword], ctx)
|
89
64
|
return false
|
@@ -132,35 +107,18 @@ module GraphQL
|
|
132
107
|
end
|
133
108
|
|
134
109
|
class << self
|
135
|
-
# @return [Class<GraphQL::Arguments>]
|
136
|
-
attr_accessor :arguments_class
|
137
|
-
|
138
110
|
def argument(*args, **kwargs, &block)
|
139
111
|
argument_defn = super(*args, **kwargs, &block)
|
140
112
|
# Add a method access
|
141
|
-
|
113
|
+
method_name = argument_defn.keyword
|
114
|
+
class_eval <<-RUBY, __FILE__, __LINE__
|
115
|
+
def #{method_name}
|
116
|
+
self[#{method_name.inspect}]
|
117
|
+
end
|
118
|
+
RUBY
|
142
119
|
argument_defn
|
143
120
|
end
|
144
121
|
|
145
|
-
prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
|
146
|
-
|
147
|
-
def to_graphql
|
148
|
-
type_defn = GraphQL::InputObjectType.new
|
149
|
-
type_defn.name = graphql_name
|
150
|
-
type_defn.description = description
|
151
|
-
type_defn.metadata[:type_class] = self
|
152
|
-
type_defn.mutation = mutation
|
153
|
-
type_defn.ast_node = ast_node
|
154
|
-
all_argument_definitions.each do |arg|
|
155
|
-
type_defn.arguments[arg.graphql_definition(silence_deprecation_warning: true).name] = arg.graphql_definition(silence_deprecation_warning: true) # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
156
|
-
end
|
157
|
-
# Make a reference to a classic-style Arguments class
|
158
|
-
self.arguments_class = GraphQL::Query::Arguments.construct_arguments_class(type_defn)
|
159
|
-
# But use this InputObject class at runtime
|
160
|
-
type_defn.arguments_class = self
|
161
|
-
type_defn
|
162
|
-
end
|
163
|
-
|
164
122
|
def kind
|
165
123
|
GraphQL::TypeKinds::INPUT_OBJECT
|
166
124
|
end
|
@@ -168,8 +126,9 @@ module GraphQL
|
|
168
126
|
# @api private
|
169
127
|
INVALID_OBJECT_MESSAGE = "Expected %{object} to be a key-value object responding to `to_h` or `to_unsafe_h`."
|
170
128
|
|
171
|
-
def validate_non_null_input(input, ctx
|
129
|
+
def validate_non_null_input(input, ctx)
|
172
130
|
result = GraphQL::Query::InputValidationResult.new
|
131
|
+
|
173
132
|
warden = ctx.warden
|
174
133
|
|
175
134
|
if input.is_a?(Array)
|
@@ -248,13 +207,6 @@ module GraphQL
|
|
248
207
|
|
249
208
|
result
|
250
209
|
end
|
251
|
-
|
252
|
-
private
|
253
|
-
|
254
|
-
def define_accessor_method(method_name)
|
255
|
-
define_method(method_name) { self[method_name] }
|
256
|
-
alias_method(method_name, method_name)
|
257
|
-
end
|
258
210
|
end
|
259
211
|
|
260
212
|
private
|
@@ -4,8 +4,6 @@ module GraphQL
|
|
4
4
|
module Interface
|
5
5
|
include GraphQL::Schema::Member::GraphQLTypeNames
|
6
6
|
module DefinitionMethods
|
7
|
-
include GraphQL::Schema::Member::CachedGraphQLDefinition
|
8
|
-
include GraphQL::Relay::TypeExtensions
|
9
7
|
include GraphQL::Schema::Member::BaseDSLMethods
|
10
8
|
# ConfigurationExtension's responsibilities are in `def included` below
|
11
9
|
include GraphQL::Schema::Member::TypeSystemHelpers
|
@@ -81,11 +79,7 @@ module GraphQL
|
|
81
79
|
end
|
82
80
|
elsif child_class < GraphQL::Schema::Object
|
83
81
|
# This is being included into an object type, make sure it's using `implements(...)`
|
84
|
-
backtrace_line =
|
85
|
-
location.base_label == "implements" &&
|
86
|
-
location.path.end_with?("schema/member/has_interfaces.rb")
|
87
|
-
end
|
88
|
-
|
82
|
+
backtrace_line = caller(0, 10).find { |line| line.include?("schema/member/has_interfaces.rb") && line.include?("in `implements'")}
|
89
83
|
if !backtrace_line
|
90
84
|
raise "Attach interfaces using `implements(#{self})`, not `include(#{self})`"
|
91
85
|
end
|
@@ -104,34 +98,11 @@ module GraphQL
|
|
104
98
|
end
|
105
99
|
end
|
106
100
|
|
107
|
-
prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
|
108
|
-
|
109
|
-
def to_graphql
|
110
|
-
type_defn = GraphQL::InterfaceType.new
|
111
|
-
type_defn.name = graphql_name
|
112
|
-
type_defn.description = description
|
113
|
-
type_defn.orphan_types = orphan_types
|
114
|
-
type_defn.type_membership_class = self.type_membership_class
|
115
|
-
type_defn.ast_node = ast_node
|
116
|
-
fields.each do |field_name, field_inst| # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
117
|
-
field_defn = field_inst.graphql_definition(silence_deprecation_warning: true)
|
118
|
-
type_defn.fields[field_defn.name] = field_defn # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
119
|
-
end
|
120
|
-
type_defn.metadata[:type_class] = self
|
121
|
-
if respond_to?(:resolve_type)
|
122
|
-
type_defn.resolve_type = method(:resolve_type)
|
123
|
-
end
|
124
|
-
type_defn
|
125
|
-
end
|
126
|
-
|
127
101
|
def kind
|
128
102
|
GraphQL::TypeKinds::INTERFACE
|
129
103
|
end
|
130
104
|
end
|
131
105
|
|
132
|
-
# Extend this _after_ `DefinitionMethods` is defined, so it will be used
|
133
|
-
extend GraphQL::Schema::Member::AcceptsDefinition
|
134
|
-
|
135
106
|
extend DefinitionMethods
|
136
107
|
|
137
108
|
def unwrap
|
@@ -89,9 +89,9 @@ module GraphQL
|
|
89
89
|
case late_bound_type
|
90
90
|
when GraphQL::Schema::LateBoundType
|
91
91
|
@schema.get_type(late_bound_type.name)
|
92
|
-
when GraphQL::Schema::List
|
92
|
+
when GraphQL::Schema::List
|
93
93
|
resolve_late_binding(late_bound_type.of_type).to_list_type
|
94
|
-
when GraphQL::Schema::NonNull
|
94
|
+
when GraphQL::Schema::NonNull
|
95
95
|
resolve_late_binding(late_bound_type.of_type).to_non_null_type
|
96
96
|
when Module
|
97
97
|
# It's a normal type -- no change required
|
@@ -103,12 +103,7 @@ module GraphQL
|
|
103
103
|
|
104
104
|
def load_constant(class_name)
|
105
105
|
const = @custom_namespace.const_get(class_name)
|
106
|
-
|
107
|
-
dup_type_class(const)
|
108
|
-
else
|
109
|
-
# Use `.to_graphql` to get a freshly-made version, not shared between schemas
|
110
|
-
const.deprecated_to_graphql
|
111
|
-
end
|
106
|
+
dup_type_class(const)
|
112
107
|
rescue NameError
|
113
108
|
# Dup the built-in so that the cached fields aren't shared
|
114
109
|
dup_type_class(@built_in_namespace.const_get(class_name))
|
@@ -16,11 +16,11 @@ module GraphQL
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def to_non_null_type
|
19
|
-
@to_non_null_type ||= GraphQL::
|
19
|
+
@to_non_null_type ||= GraphQL::Schema::NonNull.new(self)
|
20
20
|
end
|
21
21
|
|
22
22
|
def to_list_type
|
23
|
-
@to_list_type ||= GraphQL::
|
23
|
+
@to_list_type ||= GraphQL::Schema::List.new(self)
|
24
24
|
end
|
25
25
|
|
26
26
|
def inspect
|
data/lib/graphql/schema/list.rb
CHANGED
@@ -8,12 +8,6 @@ module GraphQL
|
|
8
8
|
class List < GraphQL::Schema::Wrapper
|
9
9
|
include Schema::Member::ValidatesInput
|
10
10
|
|
11
|
-
prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
|
12
|
-
|
13
|
-
def to_graphql
|
14
|
-
@of_type.graphql_definition(silence_deprecation_warning: true).to_list_type
|
15
|
-
end
|
16
|
-
|
17
11
|
# @return [GraphQL::TypeKinds::LIST]
|
18
12
|
def kind
|
19
13
|
GraphQL::TypeKinds::LIST
|
@@ -51,24 +45,15 @@ module GraphQL
|
|
51
45
|
end
|
52
46
|
end
|
53
47
|
|
54
|
-
def validate_non_null_input(value, ctx
|
48
|
+
def validate_non_null_input(value, ctx)
|
55
49
|
result = GraphQL::Query::InputValidationResult.new
|
56
50
|
ensure_array(value).each_with_index do |item, index|
|
57
51
|
item_result = of_type.validate_input(item, ctx)
|
58
|
-
|
59
|
-
if max_errors
|
60
|
-
if max_errors == 0
|
61
|
-
add_max_errros_reached_message(result)
|
62
|
-
break
|
63
|
-
end
|
64
|
-
|
65
|
-
max_errors -= 1
|
66
|
-
end
|
67
|
-
|
52
|
+
if !item_result.valid?
|
68
53
|
result.merge_result!(index, item_result)
|
69
54
|
end
|
70
55
|
end
|
71
|
-
result
|
56
|
+
result
|
72
57
|
end
|
73
58
|
|
74
59
|
private
|
@@ -81,12 +66,6 @@ module GraphQL
|
|
81
66
|
[value]
|
82
67
|
end
|
83
68
|
end
|
84
|
-
|
85
|
-
def add_max_errros_reached_message(result)
|
86
|
-
message = "Too many errors processing list variable, max validation error limit reached. Execution aborted"
|
87
|
-
item_result = GraphQL::Query::InputValidationResult.from_problem(message)
|
88
|
-
result.merge_result!(nil, item_result)
|
89
|
-
end
|
90
69
|
end
|
91
70
|
end
|
92
71
|
end
|