graphql 2.0.32 → 2.5.22
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.
- checksums.yaml +4 -4
- data/lib/generators/graphql/detailed_trace_generator.rb +77 -0
- data/lib/generators/graphql/install/mutation_root_generator.rb +2 -2
- data/lib/generators/graphql/install/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/install/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/install_generator.rb +49 -0
- data/lib/generators/graphql/orm_mutations_base.rb +1 -1
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- data/lib/generators/graphql/templates/base_connection.erb +2 -0
- data/lib/generators/graphql/templates/base_edge.erb +2 -0
- data/lib/generators/graphql/templates/base_enum.erb +2 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +2 -0
- data/lib/generators/graphql/templates/base_interface.erb +2 -0
- data/lib/generators/graphql/templates/base_object.erb +2 -0
- data/lib/generators/graphql/templates/base_resolver.erb +8 -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/create_graphql_detailed_traces.erb +10 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +2 -0
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +2 -0
- data/lib/generators/graphql/templates/node_type.erb +2 -0
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +5 -0
- data/lib/generators/graphql/type_generator.rb +1 -1
- data/lib/graphql/analysis/analyzer.rb +90 -0
- data/lib/graphql/analysis/field_usage.rb +82 -0
- data/lib/graphql/analysis/max_query_complexity.rb +20 -0
- data/lib/graphql/analysis/max_query_depth.rb +20 -0
- data/lib/graphql/analysis/query_complexity.rb +263 -0
- data/lib/graphql/analysis/query_depth.rb +58 -0
- data/lib/graphql/analysis/visitor.rb +280 -0
- data/lib/graphql/analysis.rb +95 -1
- data/lib/graphql/autoload.rb +38 -0
- data/lib/graphql/backtrace/table.rb +118 -55
- data/lib/graphql/backtrace.rb +1 -19
- data/lib/graphql/coercion_error.rb +1 -9
- data/lib/graphql/current.rb +57 -0
- data/lib/graphql/dashboard/application_controller.rb +41 -0
- data/lib/graphql/dashboard/detailed_traces.rb +47 -0
- data/lib/graphql/dashboard/installable.rb +22 -0
- data/lib/graphql/dashboard/landings_controller.rb +9 -0
- data/lib/graphql/dashboard/limiters.rb +93 -0
- data/lib/graphql/dashboard/operation_store.rb +199 -0
- data/lib/graphql/dashboard/statics/bootstrap-5.3.3.min.css +6 -0
- data/lib/graphql/dashboard/statics/bootstrap-5.3.3.min.js +7 -0
- data/lib/graphql/dashboard/statics/charts.min.css +1 -0
- data/lib/graphql/dashboard/statics/dashboard.css +30 -0
- data/lib/graphql/dashboard/statics/dashboard.js +143 -0
- data/lib/graphql/dashboard/statics/header-icon.png +0 -0
- data/lib/graphql/dashboard/statics/icon.png +0 -0
- data/lib/graphql/dashboard/statics_controller.rb +31 -0
- data/lib/graphql/dashboard/subscriptions.rb +97 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/detailed_traces/traces/index.html.erb +45 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/landings/show.html.erb +18 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/limiters/limiters/show.html.erb +62 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/not_installed.html.erb +18 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/_form.html.erb +24 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/edit.html.erb +21 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/index.html.erb +69 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/new.html.erb +7 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/index_entries/index.html.erb +39 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/index_entries/show.html.erb +32 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/operations/index.html.erb +81 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/operations/show.html.erb +71 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/subscriptions/show.html.erb +41 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/topics/index.html.erb +55 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/topics/show.html.erb +40 -0
- data/lib/graphql/dashboard/views/layouts/graphql/dashboard/application.html.erb +108 -0
- data/lib/graphql/dashboard.rb +96 -0
- data/lib/graphql/dataloader/active_record_association_source.rb +84 -0
- data/lib/graphql/dataloader/active_record_source.rb +47 -0
- data/lib/graphql/dataloader/async_dataloader.rb +112 -0
- data/lib/graphql/dataloader/null_dataloader.rb +55 -10
- data/lib/graphql/dataloader/request.rb +5 -0
- data/lib/graphql/dataloader/source.rb +35 -12
- data/lib/graphql/dataloader.rb +224 -149
- data/lib/graphql/date_encoding_error.rb +1 -1
- data/lib/graphql/dig.rb +2 -1
- data/lib/graphql/duration_encoding_error.rb +16 -0
- data/lib/graphql/execution/interpreter/argument_value.rb +5 -1
- data/lib/graphql/execution/interpreter/arguments_cache.rb +5 -10
- data/lib/graphql/execution/interpreter/resolve.rb +23 -25
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +228 -0
- data/lib/graphql/execution/interpreter/runtime.rb +363 -434
- data/lib/graphql/execution/interpreter.rb +91 -164
- data/lib/graphql/execution/lookahead.rb +105 -31
- data/lib/graphql/execution/multiplex.rb +7 -6
- data/lib/graphql/execution/next/field_resolve_step.rb +711 -0
- data/lib/graphql/execution/next/load_argument_step.rb +60 -0
- data/lib/graphql/execution/next/prepare_object_step.rb +129 -0
- data/lib/graphql/execution/next/runner.rb +389 -0
- data/lib/graphql/execution/next/selections_step.rb +37 -0
- data/lib/graphql/execution/next.rb +70 -0
- data/lib/graphql/execution.rb +1 -0
- data/lib/graphql/execution_error.rb +13 -10
- data/lib/graphql/introspection/directive_location_enum.rb +1 -1
- data/lib/graphql/introspection/directive_type.rb +7 -3
- data/lib/graphql/introspection/dynamic_fields.rb +5 -1
- data/lib/graphql/introspection/entry_points.rb +20 -6
- data/lib/graphql/introspection/enum_value_type.rb +5 -5
- data/lib/graphql/introspection/field_type.rb +13 -5
- data/lib/graphql/introspection/input_value_type.rb +21 -13
- data/lib/graphql/introspection/schema_type.rb +8 -11
- data/lib/graphql/introspection/type_type.rb +64 -28
- data/lib/graphql/invalid_name_error.rb +1 -1
- data/lib/graphql/invalid_null_error.rb +26 -17
- data/lib/graphql/language/block_string.rb +34 -18
- data/lib/graphql/language/cache.rb +13 -0
- data/lib/graphql/language/comment.rb +18 -0
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/document_from_schema_definition.rb +90 -61
- data/lib/graphql/language/lexer.rb +319 -193
- data/lib/graphql/language/nodes.rb +136 -77
- data/lib/graphql/language/parser.rb +807 -1985
- data/lib/graphql/language/printer.rb +324 -151
- data/lib/graphql/language/sanitized_printer.rb +21 -23
- data/lib/graphql/language/static_visitor.rb +171 -0
- data/lib/graphql/language/visitor.rb +23 -83
- data/lib/graphql/language.rb +71 -1
- data/lib/graphql/load_application_object_failed_error.rb +5 -1
- data/lib/graphql/pagination/array_connection.rb +6 -6
- data/lib/graphql/pagination/connection.rb +30 -1
- data/lib/graphql/pagination/connections.rb +32 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -2
- data/lib/graphql/query/context/scoped_context.rb +101 -0
- data/lib/graphql/query/context.rb +82 -144
- data/lib/graphql/query/null_context.rb +15 -18
- data/lib/graphql/query/partial.rb +179 -0
- data/lib/graphql/query/validation_pipeline.rb +4 -4
- data/lib/graphql/query/variable_validation_error.rb +1 -1
- data/lib/graphql/query/variables.rb +3 -3
- data/lib/graphql/query.rb +126 -81
- data/lib/graphql/railtie.rb +16 -6
- data/lib/graphql/rake_task.rb +3 -12
- data/lib/graphql/rubocop/graphql/base_cop.rb +1 -1
- data/lib/graphql/rubocop/graphql/field_type_in_block.rb +144 -0
- data/lib/graphql/rubocop/graphql/root_types_in_block.rb +38 -0
- data/lib/graphql/rubocop.rb +2 -0
- data/lib/graphql/schema/addition.rb +26 -13
- data/lib/graphql/schema/always_visible.rb +7 -2
- data/lib/graphql/schema/argument.rb +75 -9
- data/lib/graphql/schema/base_64_encoder.rb +3 -5
- data/lib/graphql/schema/build_from_definition.rb +123 -60
- data/lib/graphql/schema/directive/flagged.rb +4 -2
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/specified_by.rb +14 -0
- data/lib/graphql/schema/directive.rb +54 -2
- data/lib/graphql/schema/enum.rb +110 -27
- data/lib/graphql/schema/enum_value.rb +10 -2
- data/lib/graphql/schema/field/connection_extension.rb +15 -49
- data/lib/graphql/schema/field/scope_extension.rb +23 -7
- data/lib/graphql/schema/field.rb +245 -118
- data/lib/graphql/schema/field_extension.rb +34 -1
- data/lib/graphql/schema/has_single_input_argument.rb +160 -0
- data/lib/graphql/schema/input_object.rb +116 -60
- data/lib/graphql/schema/interface.rb +34 -16
- data/lib/graphql/schema/introspection_system.rb +8 -17
- data/lib/graphql/schema/late_bound_type.rb +4 -0
- data/lib/graphql/schema/list.rb +3 -3
- data/lib/graphql/schema/loader.rb +3 -4
- data/lib/graphql/schema/member/base_dsl_methods.rb +18 -2
- data/lib/graphql/schema/member/has_arguments.rb +132 -100
- data/lib/graphql/schema/member/has_authorization.rb +35 -0
- data/lib/graphql/schema/member/has_dataloader.rb +99 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +15 -0
- data/lib/graphql/schema/member/has_directives.rb +4 -4
- data/lib/graphql/schema/member/has_fields.rb +115 -15
- data/lib/graphql/schema/member/has_interfaces.rb +26 -12
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +5 -1
- data/lib/graphql/schema/member/has_validators.rb +1 -1
- data/lib/graphql/schema/member/relay_shortcuts.rb +1 -1
- data/lib/graphql/schema/member/scoped.rb +19 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +17 -4
- data/lib/graphql/schema/member/validates_input.rb +3 -3
- data/lib/graphql/schema/member.rb +6 -0
- data/lib/graphql/schema/mutation.rb +7 -0
- data/lib/graphql/schema/object.rb +34 -8
- data/lib/graphql/schema/printer.rb +9 -7
- data/lib/graphql/schema/ractor_shareable.rb +79 -0
- data/lib/graphql/schema/relay_classic_mutation.rb +6 -129
- data/lib/graphql/schema/resolver.rb +90 -32
- data/lib/graphql/schema/scalar.rb +4 -9
- data/lib/graphql/schema/subscription.rb +63 -10
- data/lib/graphql/schema/timeout.rb +19 -2
- data/lib/graphql/schema/type_expression.rb +2 -2
- data/lib/graphql/schema/union.rb +2 -2
- data/lib/graphql/schema/unique_within_type.rb +1 -1
- data/lib/graphql/schema/validator/all_validator.rb +62 -0
- data/lib/graphql/schema/validator/required_validator.rb +92 -11
- data/lib/graphql/schema/validator.rb +3 -1
- data/lib/graphql/schema/visibility/migration.rb +188 -0
- data/lib/graphql/schema/visibility/profile.rb +445 -0
- data/lib/graphql/schema/visibility/visit.rb +190 -0
- data/lib/graphql/schema/visibility.rb +311 -0
- data/lib/graphql/schema/warden.rb +275 -103
- data/lib/graphql/schema.rb +950 -210
- data/lib/graphql/static_validation/all_rules.rb +3 -3
- data/lib/graphql/static_validation/base_visitor.rb +7 -6
- data/lib/graphql/static_validation/literal_validator.rb +6 -7
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +1 -1
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +3 -2
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +3 -3
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +2 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +12 -2
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +47 -13
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +88 -25
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +10 -2
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +12 -2
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +1 -1
- data/lib/graphql/static_validation/rules/not_single_subscription_error.rb +25 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +5 -5
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -5
- data/lib/graphql/static_validation/rules/subscription_root_exists_and_single_subscription_selection.rb +26 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +7 -3
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +18 -27
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +2 -2
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +11 -2
- data/lib/graphql/static_validation/validation_context.rb +21 -5
- data/lib/graphql/static_validation/validator.rb +9 -1
- data/lib/graphql/static_validation.rb +0 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +8 -5
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +12 -10
- data/lib/graphql/subscriptions/event.rb +21 -4
- data/lib/graphql/subscriptions/serialize.rb +3 -1
- data/lib/graphql/subscriptions.rb +21 -17
- data/lib/graphql/testing/helpers.rb +161 -0
- data/lib/graphql/testing/mock_action_cable.rb +111 -0
- data/lib/graphql/testing.rb +3 -0
- data/lib/graphql/tracing/active_support_notifications_trace.rb +14 -3
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +1 -1
- data/lib/graphql/tracing/appoptics_trace.rb +7 -3
- data/lib/graphql/tracing/appoptics_tracing.rb +9 -2
- data/lib/graphql/tracing/appsignal_trace.rb +32 -59
- data/lib/graphql/tracing/appsignal_tracing.rb +2 -0
- data/lib/graphql/tracing/call_legacy_tracers.rb +66 -0
- data/lib/graphql/tracing/data_dog_trace.rb +46 -162
- data/lib/graphql/tracing/data_dog_tracing.rb +2 -0
- data/lib/graphql/tracing/detailed_trace/active_record_backend.rb +74 -0
- data/lib/graphql/tracing/detailed_trace/memory_backend.rb +60 -0
- data/lib/graphql/tracing/detailed_trace/redis_backend.rb +72 -0
- data/lib/graphql/tracing/detailed_trace.rb +156 -0
- data/lib/graphql/tracing/legacy_hooks_trace.rb +75 -0
- data/lib/graphql/tracing/legacy_trace.rb +4 -61
- data/lib/graphql/tracing/monitor_trace.rb +283 -0
- data/lib/graphql/tracing/new_relic_trace.rb +47 -54
- data/lib/graphql/tracing/new_relic_tracing.rb +2 -0
- data/lib/graphql/tracing/notifications_trace.rb +183 -37
- data/lib/graphql/tracing/notifications_tracing.rb +2 -0
- data/lib/graphql/tracing/null_trace.rb +9 -0
- data/lib/graphql/tracing/perfetto_trace/trace.proto +141 -0
- data/lib/graphql/tracing/perfetto_trace/trace_pb.rb +33 -0
- data/lib/graphql/tracing/perfetto_trace.rb +864 -0
- data/lib/graphql/tracing/platform_tracing.rb +3 -1
- data/lib/graphql/tracing/{prometheus_tracing → prometheus_trace}/graphql_collector.rb +5 -1
- data/lib/graphql/tracing/prometheus_trace.rb +73 -73
- data/lib/graphql/tracing/prometheus_tracing.rb +2 -0
- data/lib/graphql/tracing/scout_trace.rb +32 -58
- data/lib/graphql/tracing/scout_tracing.rb +2 -0
- data/lib/graphql/tracing/sentry_trace.rb +82 -0
- data/lib/graphql/tracing/statsd_trace.rb +33 -45
- data/lib/graphql/tracing/statsd_tracing.rb +2 -0
- data/lib/graphql/tracing/trace.rb +112 -1
- data/lib/graphql/tracing.rb +31 -28
- data/lib/graphql/type_kinds.rb +2 -1
- data/lib/graphql/types/iso_8601_duration.rb +77 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +44 -2
- data/lib/graphql/types/relay/edge_behaviors.rb +18 -0
- data/lib/graphql/types/relay/has_node_field.rb +13 -8
- data/lib/graphql/types/relay/has_nodes_field.rb +13 -8
- data/lib/graphql/types/relay/node_behaviors.rb +13 -2
- data/lib/graphql/types/relay/page_info_behaviors.rb +4 -0
- data/lib/graphql/types.rb +18 -10
- data/lib/graphql/unauthorized_enum_value_error.rb +13 -0
- data/lib/graphql/unauthorized_error.rb +5 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +71 -54
- data/readme.md +12 -2
- metadata +233 -37
- data/lib/graphql/analysis/ast/analyzer.rb +0 -84
- data/lib/graphql/analysis/ast/field_usage.rb +0 -57
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -22
- data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
- data/lib/graphql/analysis/ast/query_complexity.rb +0 -230
- data/lib/graphql/analysis/ast/query_depth.rb +0 -55
- data/lib/graphql/analysis/ast/visitor.rb +0 -276
- data/lib/graphql/analysis/ast.rb +0 -81
- data/lib/graphql/backtrace/inspect_result.rb +0 -50
- data/lib/graphql/backtrace/trace.rb +0 -96
- data/lib/graphql/backtrace/tracer.rb +0 -80
- data/lib/graphql/deprecation.rb +0 -9
- data/lib/graphql/filter.rb +0 -59
- data/lib/graphql/language/parser.y +0 -560
- data/lib/graphql/language/token.rb +0 -34
- data/lib/graphql/schema/base_64_bp.rb +0 -26
- data/lib/graphql/schema/invalid_type_error.rb +0 -7
- data/lib/graphql/schema/null_mask.rb +0 -11
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +0 -17
- data/lib/graphql/static_validation/type_stack.rb +0 -216
- data/lib/graphql/subscriptions/instrumentation.rb +0 -28
|
@@ -6,22 +6,31 @@ module GraphQL
|
|
|
6
6
|
module Resolve
|
|
7
7
|
# Continue field results in `results` until there's nothing else to continue.
|
|
8
8
|
# @return [void]
|
|
9
|
+
# @deprecated Call `dataloader.run` instead
|
|
9
10
|
def self.resolve_all(results, dataloader)
|
|
11
|
+
warn "#{self}.#{__method__} is deprecated; Use `dataloader.run` instead.#{caller(1, 5).map { |l| "\n #{l}"}.join}"
|
|
10
12
|
dataloader.append_job { resolve(results, dataloader) }
|
|
11
13
|
nil
|
|
12
14
|
end
|
|
13
15
|
|
|
16
|
+
# @deprecated Call `dataloader.run` instead
|
|
14
17
|
def self.resolve_each_depth(lazies_at_depth, dataloader)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
warn "#{self}.#{__method__} is deprecated; Use `dataloader.run` instead.#{caller(1, 5).map { |l| "\n #{l}"}.join}"
|
|
19
|
+
|
|
20
|
+
smallest_depth = nil
|
|
21
|
+
lazies_at_depth.each_key do |depth_key|
|
|
22
|
+
smallest_depth ||= depth_key
|
|
23
|
+
if depth_key < smallest_depth
|
|
24
|
+
smallest_depth = depth_key
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if smallest_depth
|
|
29
|
+
lazies = lazies_at_depth.delete(smallest_depth)
|
|
30
|
+
if !lazies.empty?
|
|
31
|
+
lazies.each do |l|
|
|
32
|
+
dataloader.append_job { l.value }
|
|
33
|
+
end
|
|
25
34
|
# Run lazies _and_ dataloader, see if more are enqueued
|
|
26
35
|
dataloader.run
|
|
27
36
|
resolve_each_depth(lazies_at_depth, dataloader)
|
|
@@ -30,20 +39,9 @@ module GraphQL
|
|
|
30
39
|
nil
|
|
31
40
|
end
|
|
32
41
|
|
|
33
|
-
#
|
|
34
|
-
# continue it until you get a response-ready Ruby value.
|
|
35
|
-
#
|
|
36
|
-
# `results` is one level of _depth_ of a query or multiplex.
|
|
37
|
-
#
|
|
38
|
-
# Resolve all lazy values in that depth before moving on
|
|
39
|
-
# to the next level.
|
|
40
|
-
#
|
|
41
|
-
# It's assumed that the lazies will
|
|
42
|
-
# return {Lazy} instances if there's more work to be done,
|
|
43
|
-
# or return {Hash}/{Array} if the query should be continued.
|
|
44
|
-
#
|
|
45
|
-
# @return [void]
|
|
42
|
+
# @deprecated Call `dataloader.run` instead
|
|
46
43
|
def self.resolve(results, dataloader)
|
|
44
|
+
warn "#{self}.#{__method__} is deprecated; Use `dataloader.run` instead.#{caller(1, 5).map { |l| "\n #{l}"}.join}"
|
|
47
45
|
# There might be pending jobs here that _will_ write lazies
|
|
48
46
|
# into the result hash. We should run them out, so we
|
|
49
47
|
# can be sure that all lazies will be present in the result hashes.
|
|
@@ -51,7 +49,7 @@ module GraphQL
|
|
|
51
49
|
# these approaches.
|
|
52
50
|
dataloader.run
|
|
53
51
|
next_results = []
|
|
54
|
-
while results.
|
|
52
|
+
while !results.empty?
|
|
55
53
|
result_value = results.shift
|
|
56
54
|
if result_value.is_a?(Runtime::GraphQLResultHash) || result_value.is_a?(Hash)
|
|
57
55
|
results.concat(result_value.values)
|
|
@@ -77,7 +75,7 @@ module GraphQL
|
|
|
77
75
|
end
|
|
78
76
|
end
|
|
79
77
|
|
|
80
|
-
if next_results.
|
|
78
|
+
if !next_results.empty?
|
|
81
79
|
# Any pending data loader jobs may populate the
|
|
82
80
|
# resutl arrays or result hashes accumulated in
|
|
83
81
|
# `next_results``. Run those **to completion**
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GraphQL
|
|
4
|
+
module Execution
|
|
5
|
+
class Interpreter
|
|
6
|
+
class Runtime
|
|
7
|
+
module GraphQLResult
|
|
8
|
+
def initialize(result_name, result_type, application_value, parent_result, is_non_null_in_parent, selections, is_eager, ast_node, graphql_arguments, graphql_field) # rubocop:disable Metrics/ParameterLists
|
|
9
|
+
@ast_node = ast_node
|
|
10
|
+
@graphql_arguments = graphql_arguments
|
|
11
|
+
@graphql_field = graphql_field
|
|
12
|
+
@graphql_parent = parent_result
|
|
13
|
+
@graphql_application_value = application_value
|
|
14
|
+
@graphql_result_type = result_type
|
|
15
|
+
if parent_result && parent_result.graphql_dead
|
|
16
|
+
@graphql_dead = true
|
|
17
|
+
end
|
|
18
|
+
@graphql_result_name = result_name
|
|
19
|
+
@graphql_is_non_null_in_parent = is_non_null_in_parent
|
|
20
|
+
# Jump through some hoops to avoid creating this duplicate storage if at all possible.
|
|
21
|
+
@graphql_metadata = nil
|
|
22
|
+
@graphql_selections = selections
|
|
23
|
+
@graphql_is_eager = is_eager
|
|
24
|
+
@base_path = nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# TODO test full path in Partial
|
|
28
|
+
attr_writer :base_path
|
|
29
|
+
|
|
30
|
+
def path
|
|
31
|
+
@path ||= build_path([])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def build_path(path_array)
|
|
35
|
+
graphql_result_name && path_array.unshift(graphql_result_name)
|
|
36
|
+
if @graphql_parent
|
|
37
|
+
@graphql_parent.build_path(path_array)
|
|
38
|
+
elsif @base_path
|
|
39
|
+
@base_path + path_array
|
|
40
|
+
else
|
|
41
|
+
path_array
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def depth
|
|
46
|
+
@depth ||= if @graphql_parent
|
|
47
|
+
@graphql_parent.depth + 1
|
|
48
|
+
else
|
|
49
|
+
1
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
attr_accessor :graphql_dead
|
|
54
|
+
attr_reader :graphql_parent, :graphql_result_name, :graphql_is_non_null_in_parent,
|
|
55
|
+
:graphql_application_value, :graphql_result_type, :graphql_selections, :graphql_is_eager, :ast_node, :graphql_arguments, :graphql_field
|
|
56
|
+
|
|
57
|
+
# @return [Hash] Plain-Ruby result data (`@graphql_metadata` contains Result wrapper objects)
|
|
58
|
+
attr_accessor :graphql_result_data
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class GraphQLResultHash
|
|
62
|
+
def initialize(_result_name, _result_type, _application_value, _parent_result, _is_non_null_in_parent, _selections, _is_eager, _ast_node, _graphql_arguments, graphql_field) # rubocop:disable Metrics/ParameterLists
|
|
63
|
+
super
|
|
64
|
+
@graphql_result_data = {}
|
|
65
|
+
@ordered_result_keys = nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
attr_accessor :ordered_result_keys
|
|
69
|
+
|
|
70
|
+
include GraphQLResult
|
|
71
|
+
|
|
72
|
+
attr_accessor :graphql_merged_into
|
|
73
|
+
|
|
74
|
+
def set_leaf(key, value)
|
|
75
|
+
# This is a hack.
|
|
76
|
+
# Basically, this object is merged into the root-level result at some point.
|
|
77
|
+
# But the problem is, some lazies are created whose closures retain reference to _this_
|
|
78
|
+
# object. When those lazies are resolved, they cause an update to this object.
|
|
79
|
+
#
|
|
80
|
+
# In order to return a proper top-level result, we have to update that top-level result object.
|
|
81
|
+
# In order to return a proper partial result (eg, for a directive), we have to update this object, too.
|
|
82
|
+
# Yowza.
|
|
83
|
+
if (t = @graphql_merged_into)
|
|
84
|
+
t.set_leaf(key, value)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
before_size = @graphql_result_data.size
|
|
88
|
+
@graphql_result_data[key] = value
|
|
89
|
+
after_size = @graphql_result_data.size
|
|
90
|
+
if after_size > before_size && @ordered_result_keys[before_size] != key
|
|
91
|
+
fix_result_order
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# keep this up-to-date if it's been initialized
|
|
95
|
+
@graphql_metadata && @graphql_metadata[key] = value
|
|
96
|
+
|
|
97
|
+
value
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def set_child_result(key, value)
|
|
101
|
+
if (t = @graphql_merged_into)
|
|
102
|
+
t.set_child_result(key, value)
|
|
103
|
+
end
|
|
104
|
+
before_size = @graphql_result_data.size
|
|
105
|
+
@graphql_result_data[key] = value.graphql_result_data
|
|
106
|
+
after_size = @graphql_result_data.size
|
|
107
|
+
if after_size > before_size && @ordered_result_keys[before_size] != key
|
|
108
|
+
fix_result_order
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# If we encounter some part of this response that requires metadata tracking,
|
|
112
|
+
# then create the metadata hash if necessary. It will be kept up-to-date after this.
|
|
113
|
+
(@graphql_metadata ||= @graphql_result_data.dup)[key] = value
|
|
114
|
+
value
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def delete(key)
|
|
118
|
+
@graphql_metadata && @graphql_metadata.delete(key)
|
|
119
|
+
@graphql_result_data.delete(key)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def each
|
|
123
|
+
(@graphql_metadata || @graphql_result_data).each { |k, v| yield(k, v) }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def values
|
|
127
|
+
(@graphql_metadata || @graphql_result_data).values
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def key?(k)
|
|
131
|
+
@graphql_result_data.key?(k)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def [](k)
|
|
135
|
+
(@graphql_metadata || @graphql_result_data)[k]
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def merge_into(into_result)
|
|
139
|
+
self.each do |key, value|
|
|
140
|
+
case value
|
|
141
|
+
when GraphQLResultHash
|
|
142
|
+
next_into = into_result[key]
|
|
143
|
+
if next_into
|
|
144
|
+
value.merge_into(next_into)
|
|
145
|
+
else
|
|
146
|
+
into_result.set_child_result(key, value)
|
|
147
|
+
end
|
|
148
|
+
when GraphQLResultArray
|
|
149
|
+
# There's no special handling of arrays because currently, there's no way to split the execution
|
|
150
|
+
# of a list over several concurrent flows.
|
|
151
|
+
into_result.set_child_result(key, value)
|
|
152
|
+
else
|
|
153
|
+
# We have to assume that, since this passed the `fields_will_merge` selection,
|
|
154
|
+
# that the old and new values are the same.
|
|
155
|
+
into_result.set_leaf(key, value)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
@graphql_merged_into = into_result
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def fix_result_order
|
|
162
|
+
@ordered_result_keys.each do |k|
|
|
163
|
+
if @graphql_result_data.key?(k)
|
|
164
|
+
@graphql_result_data[k] = @graphql_result_data.delete(k)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# hook for breadth-first implementations to signal when collecting results.
|
|
170
|
+
def collect_result(result_name, result_value)
|
|
171
|
+
false
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
class GraphQLResultArray
|
|
176
|
+
include GraphQLResult
|
|
177
|
+
|
|
178
|
+
def initialize(_result_name, _result_type, _application_value, _parent_result, _is_non_null_in_parent, _selections, _is_eager, _ast_node, _graphql_arguments, graphql_field) # rubocop:disable Metrics/ParameterLists
|
|
179
|
+
super
|
|
180
|
+
@graphql_result_data = []
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def graphql_skip_at(index)
|
|
184
|
+
# Mark this index as dead. It's tricky because some indices may already be storing
|
|
185
|
+
# `Lazy`s. So the runtime is still holding indexes _before_ skipping,
|
|
186
|
+
# this object has to coordinate incoming writes to account for any already-skipped indices.
|
|
187
|
+
@skip_indices ||= []
|
|
188
|
+
@skip_indices << index
|
|
189
|
+
offset_by = @skip_indices.count { |skipped_idx| skipped_idx < index}
|
|
190
|
+
delete_at_index = index - offset_by
|
|
191
|
+
@graphql_metadata && @graphql_metadata.delete_at(delete_at_index)
|
|
192
|
+
@graphql_result_data.delete_at(delete_at_index)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def set_leaf(idx, value)
|
|
196
|
+
if @skip_indices
|
|
197
|
+
offset_by = @skip_indices.count { |skipped_idx| skipped_idx < idx }
|
|
198
|
+
idx -= offset_by
|
|
199
|
+
end
|
|
200
|
+
@graphql_result_data[idx] = value
|
|
201
|
+
@graphql_metadata && @graphql_metadata[idx] = value
|
|
202
|
+
value
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def set_child_result(idx, value)
|
|
206
|
+
if @skip_indices
|
|
207
|
+
offset_by = @skip_indices.count { |skipped_idx| skipped_idx < idx }
|
|
208
|
+
idx -= offset_by
|
|
209
|
+
end
|
|
210
|
+
@graphql_result_data[idx] = value.graphql_result_data
|
|
211
|
+
# If we encounter some part of this response that requires metadata tracking,
|
|
212
|
+
# then create the metadata hash if necessary. It will be kept up-to-date after this.
|
|
213
|
+
(@graphql_metadata ||= @graphql_result_data.dup)[idx] = value
|
|
214
|
+
value
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def values
|
|
218
|
+
(@graphql_metadata || @graphql_result_data)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def [](idx)
|
|
222
|
+
(@graphql_metadata || @graphql_result_data)[idx]
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|