graphql 1.11.6 → 1.13.19
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/generators/graphql/core.rb +3 -8
- data/lib/generators/graphql/enum_generator.rb +4 -10
- data/lib/generators/graphql/field_extractor.rb +31 -0
- data/lib/generators/graphql/input_generator.rb +50 -0
- data/lib/generators/graphql/install/mutation_root_generator.rb +34 -0
- data/lib/generators/graphql/install_generator.rb +17 -7
- data/lib/generators/graphql/interface_generator.rb +7 -7
- data/lib/generators/graphql/loader_generator.rb +1 -0
- data/lib/generators/graphql/mutation_create_generator.rb +22 -0
- data/lib/generators/graphql/mutation_delete_generator.rb +22 -0
- data/lib/generators/graphql/mutation_generator.rb +6 -30
- data/lib/generators/graphql/mutation_update_generator.rb +22 -0
- data/lib/generators/graphql/object_generator.rb +12 -38
- data/lib/generators/graphql/orm_mutations_base.rb +40 -0
- data/lib/generators/graphql/relay.rb +63 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/scalar_generator.rb +4 -2
- data/lib/generators/graphql/templates/base_connection.erb +8 -0
- data/lib/generators/graphql/templates/base_edge.erb +8 -0
- data/lib/generators/graphql/templates/enum.erb +5 -1
- data/lib/generators/graphql/templates/graphql_controller.erb +2 -2
- data/lib/generators/graphql/templates/input.erb +9 -0
- data/lib/generators/graphql/templates/interface.erb +4 -2
- data/lib/generators/graphql/templates/mutation.erb +1 -1
- data/lib/generators/graphql/templates/mutation_create.erb +20 -0
- data/lib/generators/graphql/templates/mutation_delete.erb +20 -0
- data/lib/generators/graphql/templates/mutation_update.erb +21 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +5 -3
- data/lib/generators/graphql/templates/query_type.erb +1 -3
- data/lib/generators/graphql/templates/scalar.erb +3 -1
- data/lib/generators/graphql/templates/schema.erb +19 -34
- data/lib/generators/graphql/templates/union.erb +4 -2
- data/lib/generators/graphql/type_generator.rb +47 -10
- data/lib/generators/graphql/union_generator.rb +5 -5
- data/lib/graphql/analysis/analyze_query.rb +7 -0
- data/lib/graphql/analysis/ast/field_usage.rb +28 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +10 -14
- data/lib/graphql/analysis/ast/visitor.rb +14 -5
- data/lib/graphql/analysis/ast.rb +11 -2
- data/lib/graphql/argument.rb +1 -1
- data/lib/graphql/backtrace/inspect_result.rb +0 -1
- data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
- data/lib/graphql/backtrace/table.rb +34 -3
- data/lib/graphql/backtrace/traced_error.rb +0 -1
- data/lib/graphql/backtrace/tracer.rb +40 -10
- data/lib/graphql/backtrace.rb +28 -19
- data/lib/graphql/backwards_compatibility.rb +2 -1
- data/lib/graphql/base_type.rb +6 -4
- data/lib/graphql/boolean_type.rb +1 -1
- data/lib/graphql/compatibility/execution_specification.rb +1 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +2 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +2 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +2 -0
- data/lib/graphql/dataloader/null_dataloader.rb +22 -0
- data/lib/graphql/dataloader/request.rb +19 -0
- data/lib/graphql/dataloader/request_all.rb +19 -0
- data/lib/graphql/dataloader/source.rb +155 -0
- data/lib/graphql/dataloader.rb +308 -0
- data/lib/graphql/date_encoding_error.rb +16 -0
- data/lib/graphql/define/assign_global_id_field.rb +1 -1
- data/lib/graphql/define/instance_definable.rb +48 -3
- data/lib/graphql/define/type_definer.rb +5 -5
- data/lib/graphql/deprecated_dsl.rb +18 -5
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/directive/deprecated_directive.rb +1 -1
- data/lib/graphql/directive/include_directive.rb +1 -1
- data/lib/graphql/directive/skip_directive.rb +1 -1
- data/lib/graphql/directive.rb +1 -5
- data/lib/graphql/enum_type.rb +9 -3
- data/lib/graphql/execution/errors.rb +110 -7
- data/lib/graphql/execution/execute.rb +8 -1
- data/lib/graphql/execution/interpreter/arguments.rb +57 -5
- data/lib/graphql/execution/interpreter/arguments_cache.rb +49 -15
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +0 -7
- data/lib/graphql/execution/interpreter/resolve.rb +37 -25
- data/lib/graphql/execution/interpreter/runtime.rb +670 -294
- data/lib/graphql/execution/interpreter.rb +16 -16
- data/lib/graphql/execution/lazy.rb +5 -1
- data/lib/graphql/execution/lookahead.rb +2 -2
- data/lib/graphql/execution/multiplex.rb +39 -23
- data/lib/graphql/field.rb +1 -1
- data/lib/graphql/float_type.rb +1 -1
- data/lib/graphql/function.rb +4 -0
- data/lib/graphql/id_type.rb +1 -1
- data/lib/graphql/input_object_type.rb +3 -1
- data/lib/graphql/int_type.rb +1 -1
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +18 -2
- data/lib/graphql/interface_type.rb +4 -2
- data/lib/graphql/internal_representation/document.rb +2 -2
- data/lib/graphql/internal_representation/rewrite.rb +1 -1
- data/lib/graphql/introspection/directive_location_enum.rb +2 -2
- data/lib/graphql/introspection/directive_type.rb +11 -5
- data/lib/graphql/introspection/entry_points.rb +2 -2
- data/lib/graphql/introspection/enum_value_type.rb +2 -2
- data/lib/graphql/introspection/field_type.rb +3 -3
- data/lib/graphql/introspection/input_value_type.rb +10 -4
- data/lib/graphql/introspection/schema_type.rb +10 -5
- data/lib/graphql/introspection/type_type.rb +18 -12
- data/lib/graphql/introspection.rb +5 -2
- data/lib/graphql/invalid_null_error.rb +1 -1
- data/lib/graphql/language/block_string.rb +2 -6
- data/lib/graphql/language/cache.rb +37 -0
- data/lib/graphql/language/document_from_schema_definition.rb +60 -26
- data/lib/graphql/language/lexer.rb +50 -28
- data/lib/graphql/language/lexer.rl +2 -4
- data/lib/graphql/language/nodes.rb +14 -4
- data/lib/graphql/language/parser.rb +856 -825
- data/lib/graphql/language/parser.y +28 -11
- data/lib/graphql/language/printer.rb +10 -1
- data/lib/graphql/language/sanitized_printer.rb +5 -5
- data/lib/graphql/language/token.rb +0 -4
- data/lib/graphql/language.rb +1 -0
- data/lib/graphql/name_validator.rb +0 -4
- data/lib/graphql/object_type.rb +4 -4
- data/lib/graphql/pagination/active_record_relation_connection.rb +47 -3
- data/lib/graphql/pagination/connection.rb +19 -1
- data/lib/graphql/pagination/connections.rb +45 -30
- data/lib/graphql/pagination/relation_connection.rb +69 -28
- data/lib/graphql/parse_error.rb +0 -1
- data/lib/graphql/query/arguments.rb +2 -2
- data/lib/graphql/query/arguments_cache.rb +1 -2
- data/lib/graphql/query/context.rb +22 -4
- data/lib/graphql/query/executor.rb +0 -1
- data/lib/graphql/query/input_validation_result.rb +9 -0
- data/lib/graphql/query/literal_input.rb +1 -1
- data/lib/graphql/query/null_context.rb +21 -9
- data/lib/graphql/query/serial_execution/field_resolution.rb +1 -1
- data/lib/graphql/query/serial_execution.rb +1 -0
- data/lib/graphql/query/validation_pipeline.rb +3 -4
- data/lib/graphql/query/variable_validation_error.rb +3 -3
- data/lib/graphql/query/variables.rb +35 -4
- data/lib/graphql/query.rb +20 -8
- data/lib/graphql/railtie.rb +9 -1
- data/lib/graphql/rake_task.rb +3 -0
- data/lib/graphql/relay/array_connection.rb +2 -2
- data/lib/graphql/relay/base_connection.rb +7 -0
- data/lib/graphql/relay/connection_instrumentation.rb +4 -4
- data/lib/graphql/relay/connection_type.rb +16 -3
- data/lib/graphql/relay/edges_instrumentation.rb +0 -1
- data/lib/graphql/relay/global_id_resolve.rb +1 -2
- data/lib/graphql/relay/mutation.rb +2 -1
- data/lib/graphql/relay/node.rb +3 -0
- data/lib/graphql/relay/page_info.rb +1 -1
- data/lib/graphql/relay/range_add.rb +14 -5
- data/lib/graphql/relay/type_extensions.rb +2 -0
- data/lib/graphql/rubocop/graphql/base_cop.rb +36 -0
- data/lib/graphql/rubocop/graphql/default_null_true.rb +43 -0
- data/lib/graphql/rubocop/graphql/default_required_true.rb +43 -0
- data/lib/graphql/rubocop.rb +4 -0
- data/lib/graphql/scalar_type.rb +3 -1
- data/lib/graphql/schema/addition.rb +247 -0
- data/lib/graphql/schema/argument.rb +177 -21
- data/lib/graphql/schema/build_from_definition.rb +150 -55
- data/lib/graphql/schema/default_type_error.rb +2 -0
- data/lib/graphql/schema/directive/feature.rb +1 -1
- data/lib/graphql/schema/directive/flagged.rb +57 -0
- data/lib/graphql/schema/directive/include.rb +1 -1
- data/lib/graphql/schema/directive/skip.rb +1 -1
- data/lib/graphql/schema/directive/transform.rb +14 -2
- data/lib/graphql/schema/directive.rb +103 -4
- data/lib/graphql/schema/enum.rb +72 -11
- data/lib/graphql/schema/enum_value.rb +18 -6
- data/lib/graphql/schema/field/connection_extension.rb +4 -2
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +332 -111
- data/lib/graphql/schema/field_extension.rb +89 -2
- data/lib/graphql/schema/find_inherited_value.rb +4 -1
- data/lib/graphql/schema/finder.rb +5 -5
- data/lib/graphql/schema/input_object.rb +79 -55
- data/lib/graphql/schema/interface.rb +12 -20
- data/lib/graphql/schema/introspection_system.rb +1 -1
- data/lib/graphql/schema/list.rb +21 -4
- data/lib/graphql/schema/loader.rb +11 -0
- data/lib/graphql/schema/member/accepts_definition.rb +15 -3
- data/lib/graphql/schema/member/base_dsl_methods.rb +5 -16
- data/lib/graphql/schema/member/build_type.rb +4 -7
- data/lib/graphql/schema/member/cached_graphql_definition.rb +29 -2
- data/lib/graphql/schema/member/has_arguments.rb +166 -74
- data/lib/graphql/schema/member/has_deprecation_reason.rb +25 -0
- data/lib/graphql/schema/member/has_directives.rb +98 -0
- data/lib/graphql/schema/member/has_fields.rb +77 -22
- data/lib/graphql/schema/member/has_interfaces.rb +100 -0
- data/lib/graphql/schema/member/has_validators.rb +31 -0
- data/lib/graphql/schema/member/instrumentation.rb +0 -1
- data/lib/graphql/schema/member/type_system_helpers.rb +1 -1
- data/lib/graphql/schema/member/validates_input.rb +2 -2
- data/lib/graphql/schema/member.rb +5 -0
- data/lib/graphql/schema/middleware_chain.rb +1 -1
- data/lib/graphql/schema/non_null.rb +9 -3
- data/lib/graphql/schema/object.rb +40 -80
- data/lib/graphql/schema/printer.rb +16 -20
- data/lib/graphql/schema/relay_classic_mutation.rb +38 -4
- data/lib/graphql/schema/resolver/has_payload_type.rb +29 -2
- data/lib/graphql/schema/resolver.rb +110 -64
- data/lib/graphql/schema/scalar.rb +18 -2
- data/lib/graphql/schema/subscription.rb +55 -9
- data/lib/graphql/schema/timeout_middleware.rb +3 -1
- data/lib/graphql/schema/traversal.rb +1 -1
- data/lib/graphql/schema/type_expression.rb +1 -1
- data/lib/graphql/schema/type_membership.rb +18 -4
- data/lib/graphql/schema/union.rb +8 -1
- data/lib/graphql/schema/validation.rb +4 -2
- data/lib/graphql/schema/validator/allow_blank_validator.rb +29 -0
- data/lib/graphql/schema/validator/allow_null_validator.rb +26 -0
- data/lib/graphql/schema/validator/exclusion_validator.rb +33 -0
- data/lib/graphql/schema/validator/format_validator.rb +48 -0
- data/lib/graphql/schema/validator/inclusion_validator.rb +35 -0
- data/lib/graphql/schema/validator/length_validator.rb +59 -0
- data/lib/graphql/schema/validator/numericality_validator.rb +82 -0
- data/lib/graphql/schema/validator/required_validator.rb +82 -0
- data/lib/graphql/schema/validator.rb +171 -0
- data/lib/graphql/schema/warden.rb +126 -53
- data/lib/graphql/schema.rb +262 -281
- data/lib/graphql/static_validation/all_rules.rb +2 -0
- data/lib/graphql/static_validation/base_visitor.rb +9 -6
- data/lib/graphql/static_validation/definition_dependencies.rb +0 -1
- data/lib/graphql/static_validation/error.rb +3 -1
- data/lib/graphql/static_validation/literal_validator.rb +1 -1
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +4 -2
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +6 -2
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +3 -2
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +4 -2
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +90 -47
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +25 -4
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +2 -2
- data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/query_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +4 -2
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -5
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +14 -8
- data/lib/graphql/static_validation/validation_context.rb +12 -2
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +41 -10
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/string_encoding_error.rb +13 -3
- data/lib/graphql/string_type.rb +1 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +39 -8
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +0 -3
- data/lib/graphql/subscriptions/event.rb +68 -32
- data/lib/graphql/subscriptions/instrumentation.rb +0 -1
- data/lib/graphql/subscriptions/serialize.rb +34 -5
- data/lib/graphql/subscriptions/subscription_root.rb +1 -1
- data/lib/graphql/subscriptions.rb +34 -39
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +8 -21
- data/lib/graphql/tracing/appoptics_tracing.rb +3 -1
- data/lib/graphql/tracing/appsignal_tracing.rb +15 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +24 -2
- data/lib/graphql/tracing/notifications_tracing.rb +59 -0
- data/lib/graphql/tracing/platform_tracing.rb +24 -12
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +4 -1
- data/lib/graphql/tracing/skylight_tracing.rb +1 -1
- data/lib/graphql/tracing.rb +2 -2
- data/lib/graphql/types/big_int.rb +5 -1
- data/lib/graphql/types/int.rb +10 -3
- data/lib/graphql/types/iso_8601_date.rb +13 -5
- data/lib/graphql/types/iso_8601_date_time.rb +8 -1
- data/lib/graphql/types/relay/base_connection.rb +6 -91
- data/lib/graphql/types/relay/base_edge.rb +2 -34
- data/lib/graphql/types/relay/connection_behaviors.rb +174 -0
- data/lib/graphql/types/relay/default_relay.rb +31 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +64 -0
- data/lib/graphql/types/relay/has_node_field.rb +41 -0
- data/lib/graphql/types/relay/has_nodes_field.rb +41 -0
- data/lib/graphql/types/relay/node.rb +2 -4
- data/lib/graphql/types/relay/node_behaviors.rb +15 -0
- data/lib/graphql/types/relay/node_field.rb +3 -22
- data/lib/graphql/types/relay/nodes_field.rb +16 -18
- data/lib/graphql/types/relay/page_info.rb +2 -14
- data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
- data/lib/graphql/types/relay.rb +11 -3
- data/lib/graphql/types/string.rb +8 -2
- data/lib/graphql/unauthorized_error.rb +1 -1
- data/lib/graphql/union_type.rb +3 -1
- data/lib/graphql/upgrader/member.rb +1 -0
- data/lib/graphql/upgrader/schema.rb +1 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +68 -37
- data/readme.md +3 -6
- metadata +83 -113
- data/lib/graphql/execution/interpreter/hash_response.rb +0 -46
- data/lib/graphql/types/relay/base_field.rb +0 -22
- data/lib/graphql/types/relay/base_interface.rb +0 -29
- data/lib/graphql/types/relay/base_object.rb +0 -26
- /data/lib/generators/graphql/{templates → install/templates}/base_mutation.erb +0 -0
- /data/lib/generators/graphql/{templates → install/templates}/mutation_type.erb +0 -0
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# test_via: ../backtrace.rb
|
3
2
|
module GraphQL
|
4
3
|
class Backtrace
|
5
4
|
# A class for turning a context into a human-readable table or array
|
@@ -79,6 +78,25 @@ module GraphQL
|
|
79
78
|
# @return [Array] 5 items for a backtrace table (not `key`)
|
80
79
|
def build_rows(context_entry, rows:, top: false)
|
81
80
|
case context_entry
|
81
|
+
when Backtrace::Frame
|
82
|
+
field_alias = context_entry.ast_node.respond_to?(:alias) && context_entry.ast_node.alias
|
83
|
+
value = if top && @override_value
|
84
|
+
@override_value
|
85
|
+
else
|
86
|
+
value_at(@context.query.context.namespace(:interpreter)[:runtime], context_entry.path)
|
87
|
+
end
|
88
|
+
rows << [
|
89
|
+
"#{context_entry.ast_node ? context_entry.ast_node.position.join(":") : ""}",
|
90
|
+
"#{context_entry.field.path}#{field_alias ? " as #{field_alias}" : ""}",
|
91
|
+
"#{context_entry.object.object.inspect}",
|
92
|
+
context_entry.arguments.to_h.inspect, # rubocop:disable Development/ContextIsPassedCop -- unrelated method
|
93
|
+
Backtrace::InspectResult.inspect_result(value),
|
94
|
+
]
|
95
|
+
if (parent = context_entry.parent_frame)
|
96
|
+
build_rows(parent, rows: rows)
|
97
|
+
else
|
98
|
+
rows
|
99
|
+
end
|
82
100
|
when GraphQL::Query::Context::FieldResolutionContext
|
83
101
|
ctx = context_entry
|
84
102
|
field_name = "#{ctx.irep_node.owner_type.name}.#{ctx.field.name}"
|
@@ -112,16 +130,29 @@ module GraphQL
|
|
112
130
|
if object.is_a?(GraphQL::Schema::Object)
|
113
131
|
object = object.object
|
114
132
|
end
|
133
|
+
value = value_at(context_entry.namespace(:interpreter)[:runtime], [])
|
115
134
|
rows << [
|
116
135
|
"#{position}",
|
117
136
|
"#{op_type}#{op_name ? " #{op_name}" : ""}",
|
118
137
|
"#{object.inspect}",
|
119
138
|
query.variables.to_h.inspect,
|
120
|
-
Backtrace::InspectResult.inspect_result(
|
139
|
+
Backtrace::InspectResult.inspect_result(value),
|
121
140
|
]
|
122
141
|
else
|
123
|
-
raise "Unexpected get_rows subject #{context_entry.inspect}"
|
142
|
+
raise "Unexpected get_rows subject #{context_entry.class} (#{context_entry.inspect})"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def value_at(runtime, path)
|
147
|
+
response = runtime.final_result
|
148
|
+
path.each do |key|
|
149
|
+
if response && (response = response[key])
|
150
|
+
next
|
151
|
+
else
|
152
|
+
break
|
153
|
+
end
|
124
154
|
end
|
155
|
+
response
|
125
156
|
end
|
126
157
|
end
|
127
158
|
end
|
@@ -1,46 +1,76 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module GraphQL
|
3
3
|
class Backtrace
|
4
|
+
# TODO this is not fiber-friendly
|
4
5
|
module Tracer
|
5
6
|
module_function
|
6
7
|
|
7
8
|
# Implement the {GraphQL::Tracing} API.
|
8
9
|
def trace(key, metadata)
|
9
|
-
|
10
|
+
case key
|
10
11
|
when "lex", "parse"
|
11
12
|
# No context here, don't have a query yet
|
12
13
|
nil
|
13
14
|
when "execute_multiplex", "analyze_multiplex"
|
14
|
-
|
15
|
+
# No query context yet
|
16
|
+
nil
|
15
17
|
when "validate", "analyze_query", "execute_query", "execute_query_lazy"
|
16
|
-
|
18
|
+
push_key = []
|
19
|
+
if (query = metadata[:query]) || ((queries = metadata[:queries]) && (query = queries.first))
|
20
|
+
push_data = query
|
21
|
+
multiplex = query.multiplex
|
22
|
+
elsif (multiplex = metadata[:multiplex])
|
23
|
+
push_data = multiplex.queries.first
|
24
|
+
end
|
17
25
|
when "execute_field", "execute_field_lazy"
|
18
|
-
|
19
|
-
|
26
|
+
query = metadata[:query] || raise(ArgumentError, "Add `legacy: true` to use GraphQL::Backtrace without the interpreter runtime.")
|
27
|
+
multiplex = query.multiplex
|
28
|
+
push_key = metadata[:path]
|
29
|
+
parent_frame = multiplex.context[:graphql_backtrace_contexts][push_key[0..-2]]
|
30
|
+
|
31
|
+
if parent_frame.is_a?(GraphQL::Query)
|
32
|
+
parent_frame = parent_frame.context
|
33
|
+
end
|
34
|
+
|
35
|
+
push_data = Frame.new(
|
36
|
+
query: query,
|
37
|
+
path: push_key,
|
38
|
+
ast_node: metadata[:ast_node],
|
39
|
+
field: metadata[:field],
|
40
|
+
object: metadata[:object],
|
41
|
+
arguments: metadata[:arguments],
|
42
|
+
parent_frame: parent_frame,
|
43
|
+
)
|
20
44
|
else
|
21
45
|
# Custom key, no backtrace data for this
|
22
46
|
nil
|
23
47
|
end
|
24
48
|
|
25
|
-
if push_data
|
26
|
-
|
49
|
+
if push_data && multiplex
|
50
|
+
push_storage = multiplex.context[:graphql_backtrace_contexts] ||= {}
|
51
|
+
push_storage[push_key] = push_data
|
52
|
+
multiplex.context[:last_graphql_backtrace_context] = push_data
|
27
53
|
end
|
28
54
|
|
29
55
|
if key == "execute_multiplex"
|
56
|
+
multiplex_context = metadata[:multiplex].context
|
30
57
|
begin
|
31
58
|
yield
|
32
59
|
rescue StandardError => err
|
33
60
|
# This is an unhandled error from execution,
|
34
61
|
# Re-raise it with a GraphQL trace.
|
35
|
-
potential_context =
|
62
|
+
potential_context = multiplex_context[:last_graphql_backtrace_context]
|
36
63
|
|
37
|
-
if potential_context.is_a?(GraphQL::Query::Context) ||
|
64
|
+
if potential_context.is_a?(GraphQL::Query::Context) ||
|
65
|
+
potential_context.is_a?(GraphQL::Query::Context::FieldResolutionContext) ||
|
66
|
+
potential_context.is_a?(Backtrace::Frame)
|
38
67
|
raise TracedError.new(err, potential_context)
|
39
68
|
else
|
40
69
|
raise
|
41
70
|
end
|
42
71
|
ensure
|
43
|
-
|
72
|
+
multiplex_context.delete(:graphql_backtrace_contexts)
|
73
|
+
multiplex_context.delete(:last_graphql_backtrace_context)
|
44
74
|
end
|
45
75
|
else
|
46
76
|
yield
|
data/lib/graphql/backtrace.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "graphql/backtrace/inspect_result"
|
3
|
+
require "graphql/backtrace/legacy_tracer"
|
3
4
|
require "graphql/backtrace/table"
|
4
5
|
require "graphql/backtrace/traced_error"
|
5
6
|
require "graphql/backtrace/tracer"
|
@@ -9,13 +10,12 @@ module GraphQL
|
|
9
10
|
# {TracedError} provides a GraphQL backtrace with arguments and return values.
|
10
11
|
# The underlying error is available as {TracedError#cause}.
|
11
12
|
#
|
12
|
-
# WARNING: {.enable} is not threadsafe because {GraphQL::Tracing.install} is not threadsafe.
|
13
|
-
#
|
14
13
|
# @example toggling backtrace annotation
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
14
|
+
# class MySchema < GraphQL::Schema
|
15
|
+
# if Rails.env.development? || Rails.env.test?
|
16
|
+
# use GraphQL::Backtrace
|
17
|
+
# end
|
18
|
+
# end
|
19
19
|
#
|
20
20
|
class Backtrace
|
21
21
|
include Enumerable
|
@@ -23,19 +23,13 @@ module GraphQL
|
|
23
23
|
|
24
24
|
def_delegators :to_a, :each, :[]
|
25
25
|
|
26
|
-
def self.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
GraphQL::Tracing.uninstall(Backtrace::Tracer)
|
34
|
-
nil
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.use(schema_defn)
|
38
|
-
schema_defn.tracer(self::Tracer)
|
26
|
+
def self.use(schema_defn, legacy: false)
|
27
|
+
tracer = if legacy
|
28
|
+
self::LegacyTracer
|
29
|
+
else
|
30
|
+
self::Tracer
|
31
|
+
end
|
32
|
+
schema_defn.tracer(tracer)
|
39
33
|
end
|
40
34
|
|
41
35
|
def initialize(context, value: nil)
|
@@ -51,5 +45,20 @@ module GraphQL
|
|
51
45
|
def to_a
|
52
46
|
@table.to_backtrace
|
53
47
|
end
|
48
|
+
|
49
|
+
# Used for internal bookkeeping
|
50
|
+
# @api private
|
51
|
+
class Frame
|
52
|
+
attr_reader :path, :query, :ast_node, :object, :field, :arguments, :parent_frame
|
53
|
+
def initialize(path:, query:, ast_node:, object:, field:, arguments:, parent_frame:)
|
54
|
+
@path = path
|
55
|
+
@query = query
|
56
|
+
@ast_node = ast_node
|
57
|
+
@field = field
|
58
|
+
@object = object
|
59
|
+
@arguments = arguments
|
60
|
+
@parent_frame = parent_frame
|
61
|
+
end
|
62
|
+
end
|
54
63
|
end
|
55
64
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module GraphQL
|
3
3
|
# Helpers for migrating in a backwards-compatible way
|
4
|
+
# Remove this in GraphQL-Ruby 2.0, when all users of it will be gone.
|
4
5
|
# @api private
|
5
6
|
module BackwardsCompatibility
|
6
7
|
module_function
|
@@ -21,7 +22,7 @@ module GraphQL
|
|
21
22
|
backtrace = caller(0, 20)
|
22
23
|
# Find the first line in the trace that isn't library internals:
|
23
24
|
user_line = backtrace.find {|l| l !~ /lib\/graphql/ }
|
24
|
-
warn(message + "\n" + user_line + "\n")
|
25
|
+
GraphQL::Deprecation.warn(message + "\n" + user_line + "\n")
|
25
26
|
wrapper = last ? LastArgumentsWrapper : FirstArgumentsWrapper
|
26
27
|
wrapper.new(callable, from)
|
27
28
|
else
|
data/lib/graphql/base_type.rb
CHANGED
@@ -8,7 +8,7 @@ module GraphQL
|
|
8
8
|
include GraphQL::Define::InstanceDefinable
|
9
9
|
include GraphQL::Relay::TypeExtensions
|
10
10
|
|
11
|
-
|
11
|
+
deprecated_accepts_definitions :name, :description,
|
12
12
|
:introspection,
|
13
13
|
:default_scalar,
|
14
14
|
:default_relay,
|
@@ -41,7 +41,9 @@ module GraphQL
|
|
41
41
|
alias :graphql_name :name
|
42
42
|
# Future-compatible alias
|
43
43
|
# @see {GraphQL::SchemaMember}
|
44
|
-
|
44
|
+
def graphql_definition(silence_deprecation_warning: false)
|
45
|
+
itself
|
46
|
+
end
|
45
47
|
|
46
48
|
def type_class
|
47
49
|
metadata[:type_class]
|
@@ -194,7 +196,7 @@ module GraphQL
|
|
194
196
|
resolve_related_type(Object.const_get(type_arg))
|
195
197
|
else
|
196
198
|
if type_arg.respond_to?(:graphql_definition)
|
197
|
-
type_arg.graphql_definition
|
199
|
+
type_arg.graphql_definition(silence_deprecation_warning: true)
|
198
200
|
else
|
199
201
|
type_arg
|
200
202
|
end
|
@@ -224,7 +226,7 @@ module GraphQL
|
|
224
226
|
private
|
225
227
|
|
226
228
|
def warn_deprecated_coerce(alt_method_name)
|
227
|
-
warn("Coercing without a context is deprecated; use `#{alt_method_name}` if you don't want context-awareness")
|
229
|
+
GraphQL::Deprecation.warn("Coercing without a context is deprecated; use `#{alt_method_name}` if you don't want context-awareness")
|
228
230
|
end
|
229
231
|
end
|
230
232
|
end
|
data/lib/graphql/boolean_type.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
GraphQL::BOOLEAN_TYPE = GraphQL::Types::Boolean.graphql_definition
|
2
|
+
GraphQL::BOOLEAN_TYPE = GraphQL::Types::Boolean.graphql_definition(silence_deprecation_warning: true)
|
@@ -32,6 +32,7 @@ module GraphQL
|
|
32
32
|
# @param execution_strategy [<#new, #execute>] An execution strategy class
|
33
33
|
# @return [Class<Minitest::Test>] A test suite for this execution strategy
|
34
34
|
def self.build_suite(execution_strategy)
|
35
|
+
GraphQL::Deprecation.warn "#{self} will be removed from GraphQL-Ruby 2.0. There is no replacement, please open an issue on GitHub if you need support."
|
35
36
|
Class.new(Minitest::Test) do
|
36
37
|
class << self
|
37
38
|
attr_accessor :counter_schema, :specification_schema
|
@@ -7,6 +7,8 @@ module GraphQL
|
|
7
7
|
# @param execution_strategy [<#new, #execute>] An execution strategy class
|
8
8
|
# @return [Class<Minitest::Test>] A test suite for this execution strategy
|
9
9
|
def self.build_suite(execution_strategy)
|
10
|
+
GraphQL::Deprecation.warn "#{self} will be removed from GraphQL-Ruby 2.0. There is no replacement, please open an issue on GitHub if you need support."
|
11
|
+
|
10
12
|
Class.new(Minitest::Test) do
|
11
13
|
class << self
|
12
14
|
attr_accessor :lazy_schema
|
@@ -11,6 +11,8 @@ module GraphQL
|
|
11
11
|
# @yieldreturn [GraphQL::Language::Nodes::Document]
|
12
12
|
# @return [Class<Minitest::Test>] A test suite for this parse function
|
13
13
|
def self.build_suite(&block)
|
14
|
+
GraphQL::Deprecation.warn "#{self} will be removed from GraphQL-Ruby 2.0. There is no replacement, please open an issue on GitHub if you need support."
|
15
|
+
|
14
16
|
Class.new(Minitest::Test) do
|
15
17
|
include QueryAssertions
|
16
18
|
include ParseErrorSpecification
|
@@ -8,6 +8,8 @@ module GraphQL
|
|
8
8
|
# @yieldreturn [GraphQL::Language::Nodes::Document]
|
9
9
|
# @return [Class<Minitest::Test>] A test suite for this parse function
|
10
10
|
def self.build_suite(&block)
|
11
|
+
GraphQL::Deprecation.warn "#{self} will be removed from GraphQL-Ruby 2.0. There is no replacement, please open an issue on GitHub if you need support."
|
12
|
+
|
11
13
|
Class.new(Minitest::Test) do
|
12
14
|
@@parse_fn = block
|
13
15
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Dataloader
|
5
|
+
# The default implementation of dataloading -- all no-ops.
|
6
|
+
#
|
7
|
+
# The Dataloader interface isn't public, but it enables
|
8
|
+
# simple internal code while adding the option to add Dataloader.
|
9
|
+
class NullDataloader < Dataloader
|
10
|
+
# These are all no-ops because code was
|
11
|
+
# executed sychronously.
|
12
|
+
def run; end
|
13
|
+
def run_isolated; yield; end
|
14
|
+
def yield; end
|
15
|
+
|
16
|
+
def append_job
|
17
|
+
yield
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Dataloader
|
4
|
+
# @see Source#request which returns an instance of this
|
5
|
+
class Request
|
6
|
+
def initialize(source, key)
|
7
|
+
@source = source
|
8
|
+
@key = key
|
9
|
+
end
|
10
|
+
|
11
|
+
# Call this method to cause the current Fiber to wait for the results of this request.
|
12
|
+
#
|
13
|
+
# @return [Object] the object loaded for `key`
|
14
|
+
def load
|
15
|
+
@source.load(@key)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Dataloader
|
4
|
+
# @see Source#request_all which returns an instance of this.
|
5
|
+
class RequestAll < Request
|
6
|
+
def initialize(source, keys)
|
7
|
+
@source = source
|
8
|
+
@keys = keys
|
9
|
+
end
|
10
|
+
|
11
|
+
# Call this method to cause the current Fiber to wait for the results of this request.
|
12
|
+
#
|
13
|
+
# @return [Array<Object>] One object for each of `keys`
|
14
|
+
def load
|
15
|
+
@source.load_all(@keys)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Dataloader
|
5
|
+
class Source
|
6
|
+
# Called by {Dataloader} to prepare the {Source}'s internal state
|
7
|
+
# @api private
|
8
|
+
def setup(dataloader)
|
9
|
+
# These keys have been requested but haven't been fetched yet
|
10
|
+
@pending_keys = []
|
11
|
+
# These keys have been passed to `fetch` but haven't been finished yet
|
12
|
+
@fetching_keys = []
|
13
|
+
# { key => result }
|
14
|
+
@results = {}
|
15
|
+
@dataloader = dataloader
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :dataloader
|
19
|
+
|
20
|
+
# @return [Dataloader::Request] a pending request for a value from `key`. Call `.load` on that object to wait for the result.
|
21
|
+
def request(key)
|
22
|
+
if !@results.key?(key)
|
23
|
+
@pending_keys << key
|
24
|
+
end
|
25
|
+
Dataloader::Request.new(self, key)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Dataloader::Request] a pending request for a values from `keys`. Call `.load` on that object to wait for the results.
|
29
|
+
def request_all(keys)
|
30
|
+
pending_keys = keys.select { |k| !@results.key?(k) }
|
31
|
+
@pending_keys.concat(pending_keys)
|
32
|
+
Dataloader::RequestAll.new(self, keys)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param key [Object] A loading key which will be passed to {#fetch} if it isn't already in the internal cache.
|
36
|
+
# @return [Object] The result from {#fetch} for `key`. If `key` hasn't been loaded yet, the Fiber will yield until it's loaded.
|
37
|
+
def load(key)
|
38
|
+
if @results.key?(key)
|
39
|
+
result_for(key)
|
40
|
+
else
|
41
|
+
@pending_keys << key
|
42
|
+
sync
|
43
|
+
result_for(key)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param keys [Array<Object>] Loading keys which will be passed to `#fetch` (or read from the internal cache).
|
48
|
+
# @return [Object] The result from {#fetch} for `keys`. If `keys` haven't been loaded yet, the Fiber will yield until they're loaded.
|
49
|
+
def load_all(keys)
|
50
|
+
if keys.any? { |k| !@results.key?(k) }
|
51
|
+
pending_keys = keys.select { |k| !@results.key?(k) }
|
52
|
+
@pending_keys.concat(pending_keys)
|
53
|
+
sync
|
54
|
+
end
|
55
|
+
|
56
|
+
keys.map { |k| result_for(k) }
|
57
|
+
end
|
58
|
+
|
59
|
+
# Subclasses must implement this method to return a value for each of `keys`
|
60
|
+
# @param keys [Array<Object>] keys passed to {#load}, {#load_all}, {#request}, or {#request_all}
|
61
|
+
# @return [Array<Object>] A loaded value for each of `keys`. The array must match one-for-one to the list of `keys`.
|
62
|
+
def fetch(keys)
|
63
|
+
# somehow retrieve these from the backend
|
64
|
+
raise "Implement `#{self.class}#fetch(#{keys.inspect}) to return a record for each of the keys"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Wait for a batch, if there's anything to batch.
|
68
|
+
# Then run the batch and update the cache.
|
69
|
+
# @return [void]
|
70
|
+
def sync
|
71
|
+
pending_keys = @pending_keys.dup
|
72
|
+
@dataloader.yield
|
73
|
+
iterations = 0
|
74
|
+
while pending_keys.any? { |k| !@results.key?(k) }
|
75
|
+
iterations += 1
|
76
|
+
if iterations > 1000
|
77
|
+
raise "#{self.class}#sync tried 1000 times to load pending keys (#{pending_keys}), but they still weren't loaded. There is likely a circular dependency."
|
78
|
+
end
|
79
|
+
@dataloader.yield
|
80
|
+
end
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [Boolean] True if this source has any pending requests for data.
|
85
|
+
def pending?
|
86
|
+
!@pending_keys.empty?
|
87
|
+
end
|
88
|
+
|
89
|
+
# Called by {GraphQL::Dataloader} to resolve and pending requests to this source.
|
90
|
+
# @api private
|
91
|
+
# @return [void]
|
92
|
+
def run_pending_keys
|
93
|
+
if !@fetching_keys.empty?
|
94
|
+
@pending_keys -= @fetching_keys
|
95
|
+
end
|
96
|
+
return if @pending_keys.empty?
|
97
|
+
fetch_keys = @pending_keys.uniq
|
98
|
+
@fetching_keys.concat(fetch_keys)
|
99
|
+
@pending_keys = []
|
100
|
+
results = fetch(fetch_keys)
|
101
|
+
fetch_keys.each_with_index do |key, idx|
|
102
|
+
@results[key] = results[idx]
|
103
|
+
end
|
104
|
+
nil
|
105
|
+
rescue StandardError => error
|
106
|
+
fetch_keys.each { |key| @results[key] = error }
|
107
|
+
ensure
|
108
|
+
if fetch_keys
|
109
|
+
@fetching_keys -= fetch_keys
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# These arguments are given to `dataloader.with(source_class, ...)`. The object
|
114
|
+
# returned from this method is used to de-duplicate batch loads under the hood
|
115
|
+
# by using it as a Hash key.
|
116
|
+
#
|
117
|
+
# By default, the arguments are all put in an Array. To customize how this source's
|
118
|
+
# batches are merged, override this method to return something else.
|
119
|
+
#
|
120
|
+
# For example, if you pass `ActiveRecord::Relation`s to `.with(...)`, you could override
|
121
|
+
# this method to call `.to_sql` on them, thus merging `.load(...)` calls when they apply
|
122
|
+
# to equivalent relations.
|
123
|
+
#
|
124
|
+
# @param batch_args [Array<Object>]
|
125
|
+
# @param batch_kwargs [Hash]
|
126
|
+
# @return [Object]
|
127
|
+
def self.batch_key_for(*batch_args, **batch_kwargs)
|
128
|
+
[*batch_args, **batch_kwargs]
|
129
|
+
end
|
130
|
+
|
131
|
+
attr_reader :pending_keys
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
# Reads and returns the result for the key from the internal cache, or raises an error if the result was an error
|
136
|
+
# @param key [Object] key passed to {#load} or {#load_all}
|
137
|
+
# @return [Object] The result from {#fetch} for `key`.
|
138
|
+
# @api private
|
139
|
+
def result_for(key)
|
140
|
+
if !@results.key?(key)
|
141
|
+
raise GraphQL::InvariantError, <<-ERR
|
142
|
+
Fetching result for a key on #{self.class} that hasn't been loaded yet (#{key.inspect}, loaded: #{@results.keys})
|
143
|
+
|
144
|
+
This key should have been loaded already. This is a bug in GraphQL::Dataloader, please report it on GitHub: https://github.com/rmosolgo/graphql-ruby/issues/new.
|
145
|
+
ERR
|
146
|
+
end
|
147
|
+
result = @results[key]
|
148
|
+
|
149
|
+
raise result if result.class <= StandardError
|
150
|
+
|
151
|
+
result
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|