graphql 1.13.12 → 2.0.21
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_generator.rb +1 -1
- data/lib/generators/graphql/relay.rb +3 -17
- data/lib/generators/graphql/templates/schema.erb +3 -0
- data/lib/graphql/analysis/ast/field_usage.rb +3 -1
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
- 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 +43 -36
- data/lib/graphql/analysis/ast.rb +2 -12
- data/lib/graphql/analysis.rb +0 -7
- data/lib/graphql/backtrace/table.rb +2 -20
- data/lib/graphql/backtrace/trace.rb +96 -0
- data/lib/graphql/backtrace/tracer.rb +2 -3
- data/lib/graphql/backtrace.rb +7 -8
- data/lib/graphql/dataloader/null_dataloader.rb +3 -1
- data/lib/graphql/dataloader/source.rb +9 -0
- data/lib/graphql/dataloader.rb +4 -1
- data/lib/graphql/dig.rb +1 -1
- data/lib/graphql/execution/errors.rb +12 -82
- data/lib/graphql/execution/interpreter/arguments.rb +1 -1
- data/lib/graphql/execution/interpreter/arguments_cache.rb +2 -3
- data/lib/graphql/execution/interpreter/resolve.rb +26 -0
- data/lib/graphql/execution/interpreter/runtime.rb +300 -222
- data/lib/graphql/execution/interpreter.rb +187 -78
- data/lib/graphql/execution/lazy.rb +7 -21
- data/lib/graphql/execution/lookahead.rb +44 -40
- data/lib/graphql/execution/multiplex.rb +3 -174
- data/lib/graphql/execution.rb +11 -4
- data/lib/graphql/filter.rb +7 -2
- 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 +13 -6
- data/lib/graphql/introspection.rb +4 -3
- data/lib/graphql/language/document_from_schema_definition.rb +43 -44
- data/lib/graphql/language/lexer.rb +216 -1488
- data/lib/graphql/language/nodes.rb +66 -40
- data/lib/graphql/language/parser.rb +539 -510
- data/lib/graphql/language/parser.y +53 -44
- data/lib/graphql/language/printer.rb +37 -21
- data/lib/graphql/language/visitor.rb +191 -83
- data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
- data/lib/graphql/pagination/array_connection.rb +4 -2
- data/lib/graphql/pagination/connection.rb +33 -6
- data/lib/graphql/pagination/connections.rb +3 -28
- data/lib/graphql/pagination/relation_connection.rb +2 -0
- data/lib/graphql/query/context.rb +156 -196
- data/lib/graphql/query/input_validation_result.rb +10 -1
- data/lib/graphql/query/null_context.rb +1 -4
- data/lib/graphql/query/validation_pipeline.rb +12 -37
- data/lib/graphql/query/variable_validation_error.rb +2 -2
- data/lib/graphql/query/variables.rb +35 -21
- data/lib/graphql/query.rb +39 -46
- data/lib/graphql/railtie.rb +0 -104
- data/lib/graphql/rake_task/validate.rb +1 -1
- data/lib/graphql/rake_task.rb +29 -1
- data/lib/graphql/relay/range_add.rb +9 -20
- data/lib/graphql/relay.rb +0 -15
- data/lib/graphql/schema/addition.rb +7 -9
- data/lib/graphql/schema/argument.rb +38 -47
- data/lib/graphql/schema/build_from_definition.rb +47 -21
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/transform.rb +1 -1
- data/lib/graphql/schema/directive.rb +12 -23
- data/lib/graphql/schema/enum.rb +29 -41
- data/lib/graphql/schema/enum_value.rb +2 -25
- data/lib/graphql/schema/field/connection_extension.rb +4 -0
- data/lib/graphql/schema/field.rb +256 -349
- data/lib/graphql/schema/field_extension.rb +1 -4
- data/lib/graphql/schema/find_inherited_value.rb +2 -7
- data/lib/graphql/schema/input_object.rb +57 -69
- data/lib/graphql/schema/interface.rb +0 -35
- data/lib/graphql/schema/introspection_system.rb +3 -8
- data/lib/graphql/schema/late_bound_type.rb +8 -2
- data/lib/graphql/schema/list.rb +18 -9
- data/lib/graphql/schema/loader.rb +1 -2
- data/lib/graphql/schema/member/base_dsl_methods.rb +17 -19
- data/lib/graphql/schema/member/build_type.rb +5 -7
- data/lib/graphql/schema/member/has_arguments.rb +147 -56
- 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 +97 -40
- data/lib/graphql/schema/member/has_interfaces.rb +49 -10
- data/lib/graphql/schema/member/has_validators.rb +32 -6
- data/lib/graphql/schema/member/relay_shortcuts.rb +47 -2
- data/lib/graphql/schema/member/type_system_helpers.rb +17 -0
- data/lib/graphql/schema/member/validates_input.rb +3 -3
- 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 +15 -52
- data/lib/graphql/schema/relay_classic_mutation.rb +53 -42
- data/lib/graphql/schema/resolver/has_payload_type.rb +20 -10
- data/lib/graphql/schema/resolver.rb +43 -44
- data/lib/graphql/schema/scalar.rb +8 -23
- data/lib/graphql/schema/subscription.rb +0 -7
- data/lib/graphql/schema/timeout.rb +24 -28
- data/lib/graphql/schema/type_membership.rb +3 -0
- data/lib/graphql/schema/union.rb +10 -17
- data/lib/graphql/schema/validator.rb +1 -1
- data/lib/graphql/schema/warden.rb +37 -9
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +265 -968
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/base_visitor.rb +4 -21
- data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
- data/lib/graphql/static_validation/error.rb +2 -2
- data/lib/graphql/static_validation/literal_validator.rb +19 -1
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +11 -5
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +2 -2
- 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/unique_directives_per_location.rb +12 -6
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
- data/lib/graphql/static_validation/validator.rb +3 -25
- data/lib/graphql/static_validation.rb +0 -2
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -1
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
- data/lib/graphql/subscriptions/event.rb +3 -8
- data/lib/graphql/subscriptions/instrumentation.rb +0 -51
- data/lib/graphql/subscriptions.rb +32 -20
- data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
- data/lib/graphql/tracing/appoptics_trace.rb +231 -0
- data/lib/graphql/tracing/appsignal_trace.rb +77 -0
- data/lib/graphql/tracing/data_dog_trace.rb +148 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +21 -2
- data/lib/graphql/tracing/legacy_trace.rb +65 -0
- data/lib/graphql/tracing/new_relic_trace.rb +75 -0
- data/lib/graphql/tracing/notifications_trace.rb +42 -0
- data/lib/graphql/tracing/platform_trace.rb +109 -0
- data/lib/graphql/tracing/platform_tracing.rb +33 -43
- data/lib/graphql/tracing/prometheus_trace.rb +89 -0
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +1 -1
- data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
- data/lib/graphql/tracing/scout_trace.rb +72 -0
- data/lib/graphql/tracing/statsd_trace.rb +56 -0
- data/lib/graphql/tracing/trace.rb +75 -0
- data/lib/graphql/tracing.rb +16 -40
- data/lib/graphql/type_kinds.rb +6 -3
- data/lib/graphql/types/iso_8601_date.rb +4 -1
- data/lib/graphql/types/iso_8601_date_time.rb +4 -0
- data/lib/graphql/types/relay/base_connection.rb +16 -6
- data/lib/graphql/types/relay/connection_behaviors.rb +29 -27
- data/lib/graphql/types/relay/edge_behaviors.rb +16 -5
- data/lib/graphql/types/relay/node_behaviors.rb +12 -2
- data/lib/graphql/types/relay/page_info_behaviors.rb +7 -2
- data/lib/graphql/types/relay.rb +0 -3
- data/lib/graphql/types/string.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +17 -74
- metadata +33 -133
- 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/instrumentation.rb +0 -92
- data/lib/graphql/execution/lazy/resolve.rb +0 -91
- 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/language/lexer.rl +0 -260
- 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/literal_input.rb +0 -136
- 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/default_relay.rb +0 -31
- 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
@@ -11,10 +11,11 @@ module GraphQL
|
|
11
11
|
def self.extended(cls)
|
12
12
|
cls.extend(ArgumentClassAccessor)
|
13
13
|
cls.include(ArgumentObjectLoader)
|
14
|
+
cls.extend(ClassConfigured)
|
14
15
|
end
|
15
16
|
|
16
17
|
# @see {GraphQL::Schema::Argument#initialize} for parameters
|
17
|
-
# @return [GraphQL::Schema::Argument] An instance of {
|
18
|
+
# @return [GraphQL::Schema::Argument] An instance of {argument_class}, created from `*args`
|
18
19
|
def argument(*args, **kwargs, &block)
|
19
20
|
kwargs[:owner] = self
|
20
21
|
loads = kwargs[:loads]
|
@@ -78,24 +79,37 @@ module GraphQL
|
|
78
79
|
# @return [GraphQL::Schema::Argument]
|
79
80
|
def add_argument(arg_defn)
|
80
81
|
@own_arguments ||= {}
|
81
|
-
prev_defn = own_arguments[arg_defn.name]
|
82
|
+
prev_defn = @own_arguments[arg_defn.name]
|
82
83
|
case prev_defn
|
83
84
|
when nil
|
84
|
-
own_arguments[arg_defn.name] = arg_defn
|
85
|
+
@own_arguments[arg_defn.name] = arg_defn
|
85
86
|
when Array
|
86
87
|
prev_defn << arg_defn
|
87
88
|
when GraphQL::Schema::Argument
|
88
|
-
own_arguments[arg_defn.name] = [prev_defn, arg_defn]
|
89
|
+
@own_arguments[arg_defn.name] = [prev_defn, arg_defn]
|
89
90
|
else
|
90
91
|
raise "Invariant: unexpected `@own_arguments[#{arg_defn.name.inspect}]`: #{prev_defn.inspect}"
|
91
92
|
end
|
92
93
|
arg_defn
|
93
94
|
end
|
94
95
|
|
96
|
+
def remove_argument(arg_defn)
|
97
|
+
prev_defn = @own_arguments[arg_defn.name]
|
98
|
+
case prev_defn
|
99
|
+
when nil
|
100
|
+
# done
|
101
|
+
when Array
|
102
|
+
prev_defn.delete(arg_defn)
|
103
|
+
when GraphQL::Schema::Argument
|
104
|
+
@own_arguments.delete(arg_defn.name)
|
105
|
+
else
|
106
|
+
raise "Invariant: unexpected `@own_arguments[#{arg_defn.name.inspect}]`: #{prev_defn.inspect}"
|
107
|
+
end
|
108
|
+
nil
|
109
|
+
end
|
110
|
+
|
95
111
|
# @return [Hash<String => GraphQL::Schema::Argument] Arguments defined on this thing, keyed by name. Includes inherited definitions
|
96
112
|
def arguments(context = GraphQL::Query::NullContext)
|
97
|
-
inherited_arguments = ((self.is_a?(Class) && superclass.respond_to?(:arguments)) ? superclass.arguments(context) : nil)
|
98
|
-
# Local definitions override inherited ones
|
99
113
|
if own_arguments.any?
|
100
114
|
own_arguments_that_apply = {}
|
101
115
|
own_arguments.each do |name, args_entry|
|
@@ -104,31 +118,107 @@ module GraphQL
|
|
104
118
|
end
|
105
119
|
end
|
106
120
|
end
|
121
|
+
# might be nil if there are actually no arguments
|
122
|
+
own_arguments_that_apply || own_arguments
|
123
|
+
end
|
124
|
+
|
125
|
+
module ClassConfigured
|
126
|
+
def inherited(child_class)
|
127
|
+
super
|
128
|
+
child_class.extend(InheritedArguments)
|
129
|
+
end
|
107
130
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
131
|
+
module InheritedArguments
|
132
|
+
def arguments(context = GraphQL::Query::NullContext)
|
133
|
+
own_arguments = super
|
134
|
+
inherited_arguments = superclass.arguments(context)
|
135
|
+
|
136
|
+
if own_arguments.any?
|
137
|
+
if inherited_arguments.any?
|
138
|
+
# Local definitions override inherited ones
|
139
|
+
inherited_arguments.merge(own_arguments)
|
140
|
+
else
|
141
|
+
own_arguments
|
142
|
+
end
|
143
|
+
else
|
144
|
+
inherited_arguments
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def all_argument_definitions
|
149
|
+
all_defns = {}
|
150
|
+
ancestors.reverse_each do |ancestor|
|
151
|
+
if ancestor.respond_to?(:own_arguments)
|
152
|
+
all_defns.merge!(ancestor.own_arguments)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
all_defns = all_defns.values
|
156
|
+
all_defns.flatten!
|
157
|
+
all_defns
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
def get_argument(argument_name, context = GraphQL::Query::NullContext)
|
162
|
+
warden = Warden.from_context(context)
|
163
|
+
for ancestor in ancestors
|
164
|
+
if ancestor.respond_to?(:own_arguments) &&
|
165
|
+
(a = ancestor.own_arguments[argument_name]) &&
|
166
|
+
(a = Warden.visible_entry?(:visible_argument?, a, context, warden))
|
167
|
+
return a
|
168
|
+
end
|
169
|
+
end
|
170
|
+
nil
|
113
171
|
end
|
114
|
-
else
|
115
|
-
# might be nil if there are actually no arguments
|
116
|
-
own_arguments_that_apply || own_arguments
|
117
172
|
end
|
118
173
|
end
|
119
174
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
175
|
+
module FieldConfigured
|
176
|
+
def arguments(context = GraphQL::Query::NullContext)
|
177
|
+
own_arguments = super
|
178
|
+
if defined?(@resolver_class) && @resolver_class
|
179
|
+
inherited_arguments = @resolver_class.field_arguments(context)
|
180
|
+
if own_arguments.any?
|
181
|
+
if inherited_arguments.any?
|
182
|
+
inherited_arguments.merge(own_arguments)
|
183
|
+
else
|
184
|
+
own_arguments
|
185
|
+
end
|
186
|
+
else
|
187
|
+
inherited_arguments
|
126
188
|
end
|
189
|
+
else
|
190
|
+
own_arguments
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def all_argument_definitions
|
195
|
+
if defined?(@resolver_class) && @resolver_class
|
196
|
+
all_defns = {}
|
197
|
+
@resolver_class.all_field_argument_definitions.each do |arg_defn|
|
198
|
+
key = arg_defn.graphql_name
|
199
|
+
case (current_value = all_defns[key])
|
200
|
+
when nil
|
201
|
+
all_defns[key] = arg_defn
|
202
|
+
when Array
|
203
|
+
current_value << arg_defn
|
204
|
+
when GraphQL::Schema::Argument
|
205
|
+
all_defns[key] = [current_value, arg_defn]
|
206
|
+
else
|
207
|
+
raise "Invariant: Unexpected argument definition, #{current_value.class}: #{current_value.inspect}"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
all_defns.merge!(own_arguments)
|
211
|
+
all_defns = all_defns.values
|
212
|
+
all_defns.flatten!
|
213
|
+
all_defns
|
214
|
+
else
|
215
|
+
super
|
127
216
|
end
|
128
|
-
else
|
129
|
-
all_defns = own_arguments
|
130
217
|
end
|
131
|
-
|
218
|
+
end
|
219
|
+
|
220
|
+
def all_argument_definitions
|
221
|
+
all_defns = own_arguments.values
|
132
222
|
all_defns.flatten!
|
133
223
|
all_defns
|
134
224
|
end
|
@@ -136,17 +226,11 @@ module GraphQL
|
|
136
226
|
# @return [GraphQL::Schema::Argument, nil] Argument defined on this thing, fetched by name.
|
137
227
|
def get_argument(argument_name, context = GraphQL::Query::NullContext)
|
138
228
|
warden = Warden.from_context(context)
|
139
|
-
if
|
140
|
-
|
141
|
-
|
229
|
+
if (arg_config = own_arguments[argument_name]) && (visible_arg = Warden.visible_entry?(:visible_argument?, arg_config, context, warden))
|
230
|
+
visible_arg
|
231
|
+
elsif defined?(@resolver_class) && @resolver_class
|
232
|
+
@resolver_class.get_field_argument(argument_name, context)
|
142
233
|
else
|
143
|
-
for ancestor in ancestors
|
144
|
-
if ancestor.respond_to?(:own_arguments) &&
|
145
|
-
(a = ancestor.own_arguments[argument_name]) &&
|
146
|
-
(a = Warden.visible_entry?(:visible_argument?, a, context, warden))
|
147
|
-
return a
|
148
|
-
end
|
149
|
-
end
|
150
234
|
nil
|
151
235
|
end
|
152
236
|
end
|
@@ -167,7 +251,7 @@ module GraphQL
|
|
167
251
|
# @return [Interpreter::Arguments, Execution::Lazy<Interpeter::Arguments>]
|
168
252
|
def coerce_arguments(parent_object, values, context, &block)
|
169
253
|
# Cache this hash to avoid re-merging it
|
170
|
-
arg_defns =
|
254
|
+
arg_defns = context.warden.arguments(self)
|
171
255
|
total_args_count = arg_defns.size
|
172
256
|
|
173
257
|
finished_args = nil
|
@@ -181,7 +265,7 @@ module GraphQL
|
|
181
265
|
argument_values = {}
|
182
266
|
resolved_args_count = 0
|
183
267
|
raised_error = false
|
184
|
-
arg_defns.each do |
|
268
|
+
arg_defns.each do |arg_defn|
|
185
269
|
context.dataloader.append_job do
|
186
270
|
begin
|
187
271
|
arg_defn.coerce_into_values(parent_object, values, context, argument_values)
|
@@ -223,7 +307,12 @@ module GraphQL
|
|
223
307
|
# but not for directives.
|
224
308
|
# TODO apply static validations on schema definitions?
|
225
309
|
def validate_directive_argument(arg_defn, value)
|
226
|
-
|
310
|
+
# this is only implemented on directives.
|
311
|
+
nil
|
312
|
+
end
|
313
|
+
|
314
|
+
module HasDirectiveArguments
|
315
|
+
def validate_directive_argument(arg_defn, value)
|
227
316
|
if value.nil? && arg_defn.type.non_null?
|
228
317
|
raise ArgumentError, "#{arg_defn.path} is required, but no value was given"
|
229
318
|
end
|
@@ -281,8 +370,14 @@ module GraphQL
|
|
281
370
|
end
|
282
371
|
# Double-check that the located object is actually of this type
|
283
372
|
# (Don't want to allow arbitrary access to objects this way)
|
284
|
-
|
285
|
-
context.schema.after_lazy(
|
373
|
+
maybe_lazy_resolve_type = context.schema.resolve_type(argument.loads, application_object, context)
|
374
|
+
context.schema.after_lazy(maybe_lazy_resolve_type) do |resolve_type_result|
|
375
|
+
if resolve_type_result.is_a?(Array) && resolve_type_result.size == 2
|
376
|
+
application_object_type, application_object = resolve_type_result
|
377
|
+
else
|
378
|
+
application_object_type = resolve_type_result
|
379
|
+
# application_object is already assigned
|
380
|
+
end
|
286
381
|
possible_object_types = context.warden.possible_types(argument.loads)
|
287
382
|
if !possible_object_types.include?(application_object_type)
|
288
383
|
err = GraphQL::LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object)
|
@@ -291,26 +386,22 @@ module GraphQL
|
|
291
386
|
# This object was loaded successfully
|
292
387
|
# and resolved to the right type,
|
293
388
|
# now apply the `.authorized?` class method if there is one
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
389
|
+
context.schema.after_lazy(application_object_type.authorized?(application_object, context)) do |authed|
|
390
|
+
if authed
|
391
|
+
application_object
|
392
|
+
else
|
393
|
+
err = GraphQL::UnauthorizedError.new(
|
394
|
+
object: application_object,
|
395
|
+
type: application_object_type,
|
396
|
+
context: context,
|
397
|
+
)
|
398
|
+
if self.respond_to?(:unauthorized_object)
|
399
|
+
err.set_backtrace(caller)
|
400
|
+
unauthorized_object(err)
|
298
401
|
else
|
299
|
-
err
|
300
|
-
object: application_object,
|
301
|
-
type: class_based_type,
|
302
|
-
context: context,
|
303
|
-
)
|
304
|
-
if self.respond_to?(:unauthorized_object)
|
305
|
-
err.set_backtrace(caller)
|
306
|
-
unauthorized_object(err)
|
307
|
-
else
|
308
|
-
raise err
|
309
|
-
end
|
402
|
+
raise err
|
310
403
|
end
|
311
404
|
end
|
312
|
-
else
|
313
|
-
application_object
|
314
405
|
end
|
315
406
|
end
|
316
407
|
end
|
@@ -322,7 +413,7 @@ module GraphQL
|
|
322
413
|
end
|
323
414
|
end
|
324
415
|
|
325
|
-
NO_ARGUMENTS =
|
416
|
+
NO_ARGUMENTS = GraphQL::EmptyObjects::EMPTY_HASH
|
326
417
|
def own_arguments
|
327
418
|
@own_arguments || NO_ARGUMENTS
|
328
419
|
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
|
@@ -5,17 +5,16 @@ module GraphQL
|
|
5
5
|
class Member
|
6
6
|
module HasDeprecationReason
|
7
7
|
# @return [String, nil] Explains why this member was deprecated (if present, this will be marked deprecated in introspection)
|
8
|
-
|
9
|
-
dir = self.directives.find { |d| d.is_a?(GraphQL::Schema::Directive::Deprecated) }
|
10
|
-
dir && dir.arguments[:reason] # rubocop:disable Development/ContextIsPassedCop -- definition-related
|
11
|
-
end
|
8
|
+
attr_reader :deprecation_reason
|
12
9
|
|
13
10
|
# Set the deprecation reason for this member, or remove it by assigning `nil`
|
14
11
|
# @param text [String, nil]
|
15
12
|
def deprecation_reason=(text)
|
13
|
+
@deprecation_reason = text
|
16
14
|
if text.nil?
|
17
15
|
remove_directive(GraphQL::Schema::Directive::Deprecated)
|
18
16
|
else
|
17
|
+
# This removes a previously-attached directive, if there is one:
|
19
18
|
directive(GraphQL::Schema::Directive::Deprecated, reason: text)
|
20
19
|
end
|
21
20
|
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.
|
@@ -11,8 +21,7 @@ module GraphQL
|
|
11
21
|
# @return [void]
|
12
22
|
def directive(dir_class, **options)
|
13
23
|
@own_directives ||= []
|
14
|
-
|
15
|
-
@own_directives << dir_class.new(self, **options)
|
24
|
+
HasDirectives.add_directive(self, @own_directives, dir_class, options)
|
16
25
|
nil
|
17
26
|
end
|
18
27
|
|
@@ -20,78 +29,89 @@ module GraphQL
|
|
20
29
|
# @param dir_class [Class<GraphQL::Schema::Directive>]
|
21
30
|
# @return [viod]
|
22
31
|
def remove_directive(dir_class)
|
23
|
-
@own_directives
|
32
|
+
HasDirectives.remove_directive(@own_directives, dir_class)
|
24
33
|
nil
|
25
34
|
end
|
26
35
|
|
27
|
-
NO_DIRECTIVES = [].freeze
|
28
|
-
|
29
36
|
def directives
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
37
|
+
HasDirectives.get_directives(self, @own_directives, :directives)
|
38
|
+
end
|
39
|
+
|
40
|
+
class << self
|
41
|
+
def add_directive(schema_member, directives, directive_class, directive_options)
|
42
|
+
remove_directive(directives, directive_class) unless directive_class.repeatable?
|
43
|
+
directives << directive_class.new(schema_member, **directive_options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def remove_directive(directives, directive_class)
|
47
|
+
directives && directives.reject! { |d| d.is_a?(directive_class) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_directives(schema_member, directives, directives_method)
|
51
|
+
case schema_member
|
52
|
+
when Class
|
53
|
+
inherited_directives = if schema_member.superclass.respond_to?(directives_method)
|
54
|
+
get_directives(schema_member.superclass, schema_member.superclass.public_send(directives_method), directives_method)
|
55
|
+
else
|
56
|
+
GraphQL::EmptyObjects::EMPTY_ARRAY
|
57
|
+
end
|
58
|
+
if inherited_directives.any? && directives
|
59
|
+
dirs = []
|
60
|
+
merge_directives(dirs, inherited_directives)
|
61
|
+
merge_directives(dirs, directives)
|
62
|
+
dirs
|
63
|
+
elsif directives
|
64
|
+
directives
|
65
|
+
elsif inherited_directives.any?
|
66
|
+
inherited_directives
|
67
|
+
else
|
68
|
+
GraphQL::EmptyObjects::EMPTY_ARRAY
|
69
|
+
end
|
70
|
+
when Module
|
71
|
+
dirs = nil
|
72
|
+
schema_member.ancestors.reverse_each do |ancestor|
|
73
|
+
if ancestor.respond_to?(:own_directives) &&
|
74
|
+
(anc_dirs = ancestor.own_directives).any?
|
75
|
+
dirs ||= []
|
76
|
+
merge_directives(dirs, anc_dirs)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
if directives
|
54
80
|
dirs ||= []
|
55
|
-
merge_directives(dirs,
|
81
|
+
merge_directives(dirs, directives)
|
56
82
|
end
|
83
|
+
dirs || GraphQL::EmptyObjects::EMPTY_ARRAY
|
84
|
+
when HasDirectives
|
85
|
+
directives || GraphQL::EmptyObjects::EMPTY_ARRAY
|
86
|
+
else
|
87
|
+
raise "Invariant: how could #{schema_member} not be a Class, Module, or instance of HasDirectives?"
|
57
88
|
end
|
58
|
-
if own_directives
|
59
|
-
dirs ||= []
|
60
|
-
merge_directives(dirs, own_directives)
|
61
|
-
end
|
62
|
-
dirs || NO_DIRECTIVES
|
63
|
-
when HasDirectives
|
64
|
-
@own_directives || NO_DIRECTIVES
|
65
|
-
else
|
66
|
-
raise "Invariant: how could #{self} not be a Class, Module, or instance of HasDirectives?"
|
67
89
|
end
|
68
|
-
end
|
69
|
-
|
70
|
-
protected
|
71
|
-
|
72
|
-
def own_directives
|
73
|
-
@own_directives
|
74
|
-
end
|
75
90
|
|
76
|
-
|
91
|
+
private
|
77
92
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
93
|
+
# Modify `target` by adding items from `dirs` such that:
|
94
|
+
# - Any name conflict is overriden by the incoming member of `dirs`
|
95
|
+
# - Any other member of `dirs` is appended
|
96
|
+
# @param target [Array<GraphQL::Schema::Directive>]
|
97
|
+
# @param dirs [Array<GraphQL::Schema::Directive>]
|
98
|
+
# @return [void]
|
99
|
+
def merge_directives(target, dirs)
|
100
|
+
dirs.each do |dir|
|
101
|
+
if (idx = target.find_index { |d| d.graphql_name == dir.graphql_name })
|
102
|
+
target.slice!(idx)
|
103
|
+
target.insert(idx, dir)
|
104
|
+
else
|
105
|
+
target << dir
|
106
|
+
end
|
91
107
|
end
|
108
|
+
nil
|
92
109
|
end
|
93
|
-
nil
|
94
110
|
end
|
111
|
+
|
112
|
+
protected
|
113
|
+
|
114
|
+
attr_accessor :own_directives
|
95
115
|
end
|
96
116
|
end
|
97
117
|
end
|