graphql 1.10.1 → 1.13.0
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/core.rb +18 -2
- data/lib/generators/graphql/install_generator.rb +36 -6
- data/lib/generators/graphql/loader_generator.rb +1 -0
- data/lib/generators/graphql/mutation_generator.rb +2 -1
- data/lib/generators/graphql/object_generator.rb +54 -9
- data/lib/generators/graphql/relay.rb +63 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- 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/base_enum.erb +2 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +2 -0
- data/lib/generators/graphql/templates/base_interface.erb +2 -0
- data/lib/generators/graphql/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/templates/base_object.erb +2 -0
- data/lib/generators/graphql/templates/base_scalar.erb +2 -0
- data/lib/generators/graphql/templates/base_union.erb +2 -0
- data/lib/generators/graphql/templates/enum.erb +2 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +16 -12
- data/lib/generators/graphql/templates/interface.erb +2 -0
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +2 -0
- data/lib/generators/graphql/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +3 -1
- data/lib/generators/graphql/templates/query_type.erb +3 -3
- data/lib/generators/graphql/templates/scalar.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +21 -33
- data/lib/generators/graphql/templates/union.erb +3 -1
- data/lib/generators/graphql/type_generator.rb +1 -1
- data/lib/graphql/analysis/analyze_query.rb +7 -0
- data/lib/graphql/analysis/ast/field_usage.rb +24 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +126 -109
- data/lib/graphql/analysis/ast/visitor.rb +13 -5
- data/lib/graphql/analysis/ast.rb +11 -2
- data/lib/graphql/argument.rb +3 -3
- 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 -9
- data/lib/graphql/backtrace.rb +28 -19
- data/lib/graphql/backwards_compatibility.rb +2 -1
- data/lib/graphql/base_type.rb +1 -1
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +2 -2
- 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/define/assign_global_id_field.rb +2 -2
- data/lib/graphql/define/defined_object_proxy.rb +1 -1
- data/lib/graphql/define/instance_definable.rb +34 -4
- 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.rb +4 -4
- data/lib/graphql/enum_type.rb +7 -1
- data/lib/graphql/execution/errors.rb +110 -7
- data/lib/graphql/execution/execute.rb +8 -1
- data/lib/graphql/execution/instrumentation.rb +1 -1
- data/lib/graphql/execution/interpreter/argument_value.rb +28 -0
- data/lib/graphql/execution/interpreter/arguments.rb +88 -0
- data/lib/graphql/execution/interpreter/arguments_cache.rb +103 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +18 -0
- data/lib/graphql/execution/interpreter/resolve.rb +37 -25
- data/lib/graphql/execution/interpreter/runtime.rb +685 -421
- data/lib/graphql/execution/interpreter.rb +42 -13
- data/lib/graphql/execution/lazy.rb +5 -1
- data/lib/graphql/execution/lookahead.rb +25 -110
- data/lib/graphql/execution/multiplex.rb +37 -25
- data/lib/graphql/field.rb +5 -1
- data/lib/graphql/function.rb +4 -0
- data/lib/graphql/input_object_type.rb +6 -0
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +18 -2
- data/lib/graphql/interface_type.rb +7 -0
- data/lib/graphql/internal_representation/document.rb +2 -2
- data/lib/graphql/internal_representation/rewrite.rb +1 -1
- data/lib/graphql/internal_representation/scope.rb +2 -2
- data/lib/graphql/internal_representation/visit.rb +2 -2
- data/lib/graphql/introspection/directive_type.rb +8 -4
- 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 +9 -5
- data/lib/graphql/introspection/input_value_type.rb +15 -3
- data/lib/graphql/introspection/introspection_query.rb +6 -92
- data/lib/graphql/introspection/schema_type.rb +4 -4
- data/lib/graphql/introspection/type_type.rb +16 -12
- data/lib/graphql/introspection.rb +96 -0
- data/lib/graphql/invalid_null_error.rb +18 -0
- data/lib/graphql/language/block_string.rb +20 -5
- data/lib/graphql/language/cache.rb +37 -0
- data/lib/graphql/language/document_from_schema_definition.rb +73 -25
- data/lib/graphql/language/lexer.rb +4 -3
- data/lib/graphql/language/lexer.rl +3 -3
- data/lib/graphql/language/nodes.rb +51 -89
- data/lib/graphql/language/parser.rb +552 -530
- data/lib/graphql/language/parser.y +114 -99
- data/lib/graphql/language/printer.rb +7 -2
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/token.rb +0 -4
- data/lib/graphql/language/visitor.rb +2 -2
- data/lib/graphql/language.rb +2 -0
- data/lib/graphql/name_validator.rb +2 -7
- data/lib/graphql/object_type.rb +44 -35
- data/lib/graphql/pagination/active_record_relation_connection.rb +14 -1
- data/lib/graphql/pagination/array_connection.rb +2 -2
- data/lib/graphql/pagination/connection.rb +75 -20
- data/lib/graphql/pagination/connections.rb +83 -31
- data/lib/graphql/pagination/relation_connection.rb +34 -14
- data/lib/graphql/parse_error.rb +0 -1
- data/lib/graphql/query/arguments.rb +4 -3
- data/lib/graphql/query/arguments_cache.rb +1 -2
- data/lib/graphql/query/context.rb +42 -7
- data/lib/graphql/query/executor.rb +0 -1
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +23 -6
- data/lib/graphql/query/literal_input.rb +1 -1
- data/lib/graphql/query/null_context.rb +24 -8
- 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 +5 -2
- data/lib/graphql/query/variable_validation_error.rb +1 -1
- data/lib/graphql/query/variables.rb +14 -4
- data/lib/graphql/query.rb +68 -13
- data/lib/graphql/railtie.rb +9 -1
- data/lib/graphql/rake_task.rb +12 -9
- data/lib/graphql/relay/array_connection.rb +10 -12
- data/lib/graphql/relay/base_connection.rb +26 -13
- data/lib/graphql/relay/connection_instrumentation.rb +4 -4
- data/lib/graphql/relay/connection_type.rb +1 -1
- data/lib/graphql/relay/edges_instrumentation.rb +0 -1
- data/lib/graphql/relay/mutation.rb +1 -0
- data/lib/graphql/relay/node.rb +3 -0
- data/lib/graphql/relay/range_add.rb +23 -9
- data/lib/graphql/relay/relation_connection.rb +8 -10
- 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 +16 -1
- data/lib/graphql/schema/addition.rb +247 -0
- data/lib/graphql/schema/argument.rb +210 -12
- data/lib/graphql/schema/base_64_encoder.rb +2 -0
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +3 -1
- data/lib/graphql/schema/build_from_definition.rb +213 -86
- data/lib/graphql/schema/default_type_error.rb +2 -0
- data/lib/graphql/schema/directive/deprecated.rb +1 -1
- 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 +78 -2
- data/lib/graphql/schema/enum.rb +80 -9
- data/lib/graphql/schema/enum_value.rb +17 -6
- data/lib/graphql/schema/field/connection_extension.rb +46 -30
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +285 -133
- 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 +97 -89
- data/lib/graphql/schema/interface.rb +24 -19
- data/lib/graphql/schema/late_bound_type.rb +2 -2
- data/lib/graphql/schema/list.rb +7 -1
- data/lib/graphql/schema/loader.rb +137 -103
- data/lib/graphql/schema/member/accepts_definition.rb +8 -1
- data/lib/graphql/schema/member/base_dsl_methods.rb +15 -19
- data/lib/graphql/schema/member/build_type.rb +14 -7
- data/lib/graphql/schema/member/has_arguments.rb +205 -12
- data/lib/graphql/schema/member/has_ast_node.rb +4 -1
- 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 +95 -30
- data/lib/graphql/schema/member/has_interfaces.rb +90 -0
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +15 -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 +3 -3
- data/lib/graphql/schema/member.rb +6 -0
- data/lib/graphql/schema/middleware_chain.rb +1 -1
- data/lib/graphql/schema/mutation.rb +4 -0
- data/lib/graphql/schema/non_null.rb +5 -0
- data/lib/graphql/schema/object.rb +47 -46
- data/lib/graphql/schema/possible_types.rb +9 -4
- data/lib/graphql/schema/printer.rb +16 -34
- data/lib/graphql/schema/relay_classic_mutation.rb +32 -4
- data/lib/graphql/schema/resolver/has_payload_type.rb +34 -4
- data/lib/graphql/schema/resolver.rb +123 -63
- data/lib/graphql/schema/scalar.rb +11 -1
- data/lib/graphql/schema/subscription.rb +57 -21
- data/lib/graphql/schema/timeout.rb +29 -15
- data/lib/graphql/schema/timeout_middleware.rb +3 -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 +41 -1
- data/lib/graphql/schema/unique_within_type.rb +1 -2
- data/lib/graphql/schema/validation.rb +12 -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 +68 -0
- data/lib/graphql/schema/validator.rb +174 -0
- data/lib/graphql/schema/warden.rb +153 -28
- data/lib/graphql/schema.rb +364 -330
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/base_visitor.rb +8 -5
- 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 +51 -26
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +44 -87
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +22 -6
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +28 -22
- 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/fields_will_merge.rb +79 -43
- 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/required_arguments_are_present.rb +1 -1
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +6 -7
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +9 -10
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +8 -8
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +4 -2
- data/lib/graphql/static_validation/validation_context.rb +9 -3
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +42 -8
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/string_encoding_error.rb +13 -3
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +118 -19
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +81 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +21 -0
- data/lib/graphql/subscriptions/event.rb +81 -30
- data/lib/graphql/subscriptions/instrumentation.rb +0 -1
- data/lib/graphql/subscriptions/serialize.rb +33 -6
- data/lib/graphql/subscriptions/subscription_root.rb +15 -4
- data/lib/graphql/subscriptions.rb +88 -45
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +2 -1
- data/lib/graphql/tracing/appoptics_tracing.rb +173 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +15 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +1 -12
- data/lib/graphql/tracing/platform_tracing.rb +43 -17
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +4 -1
- data/lib/graphql/tracing/scout_tracing.rb +11 -0
- data/lib/graphql/tracing/skylight_tracing.rb +1 -1
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +9 -33
- 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 +3 -3
- data/lib/graphql/types/iso_8601_date_time.rb +25 -10
- data/lib/graphql/types/relay/base_connection.rb +6 -90
- data/lib/graphql/types/relay/base_edge.rb +2 -34
- data/lib/graphql/types/relay/connection_behaviors.rb +156 -0
- data/lib/graphql/types/relay/default_relay.rb +27 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +53 -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 +2 -20
- data/lib/graphql/types/relay/nodes_field.rb +2 -20
- 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 +2 -2
- data/lib/graphql/union_type.rb +2 -0
- 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 +65 -31
- data/readme.md +3 -6
- metadata +77 -112
- data/lib/graphql/execution/interpreter/hash_response.rb +0 -46
- data/lib/graphql/literal_validation_error.rb +0 -6
- 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
@@ -1,45 +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
|
-
metadata[:
|
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
|
+
)
|
19
44
|
else
|
20
45
|
# Custom key, no backtrace data for this
|
21
46
|
nil
|
22
47
|
end
|
23
48
|
|
24
|
-
if push_data
|
25
|
-
|
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
|
26
53
|
end
|
27
54
|
|
28
55
|
if key == "execute_multiplex"
|
56
|
+
multiplex_context = metadata[:multiplex].context
|
29
57
|
begin
|
30
58
|
yield
|
31
59
|
rescue StandardError => err
|
32
60
|
# This is an unhandled error from execution,
|
33
61
|
# Re-raise it with a GraphQL trace.
|
34
|
-
potential_context =
|
62
|
+
potential_context = multiplex_context[:last_graphql_backtrace_context]
|
35
63
|
|
36
|
-
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)
|
37
67
|
raise TracedError.new(err, potential_context)
|
38
68
|
else
|
39
69
|
raise
|
40
70
|
end
|
41
71
|
ensure
|
42
|
-
|
72
|
+
multiplex_context.delete(:graphql_backtrace_contexts)
|
73
|
+
multiplex_context.delete(:last_graphql_backtrace_context)
|
43
74
|
end
|
44
75
|
else
|
45
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
@@ -224,7 +224,7 @@ module GraphQL
|
|
224
224
|
private
|
225
225
|
|
226
226
|
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")
|
227
|
+
GraphQL::Deprecation.warn("Coercing without a context is deprecated; use `#{alt_method_name}` if you don't want context-awareness")
|
228
228
|
end
|
229
229
|
end
|
230
230
|
end
|
@@ -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 <<-ERR
|
142
|
+
Invariant: 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
|