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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<% content_for(:title, "Subscriptions - Topics") %>
|
|
2
|
+
<div class="row mt-3 justify-content-between">
|
|
3
|
+
<div class="col-auto">
|
|
4
|
+
<h3>
|
|
5
|
+
<%= pluralize(@all_topics_count, "Subscription Topic") %>
|
|
6
|
+
</h3>
|
|
7
|
+
</div>
|
|
8
|
+
<div class="col-auto">
|
|
9
|
+
<%= button_tag "Clear All", class: "btn btn-outline-danger", data: { subscriptions_delete_all: graphql_dashboard.subscriptions_clear_all_path } %>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<table class="table table-striped">
|
|
14
|
+
<thead>
|
|
15
|
+
<tr>
|
|
16
|
+
<th>Name</th>
|
|
17
|
+
<th># Subscriptions</th>
|
|
18
|
+
<th>Last Triggered At</th>
|
|
19
|
+
</tr>
|
|
20
|
+
</thead>
|
|
21
|
+
<tbody>
|
|
22
|
+
<% if @all_topics_count == 0 %>
|
|
23
|
+
<tr>
|
|
24
|
+
<td colspan="3" class="text-center">
|
|
25
|
+
<em>There aren't any subscriptions right now.</em>
|
|
26
|
+
</td>
|
|
27
|
+
</tr>
|
|
28
|
+
<% else %>
|
|
29
|
+
<% @topics.each do |topic| %>
|
|
30
|
+
<tr>
|
|
31
|
+
<td><%= link_to(topic.name, graphql_dashboard.subscriptions_topic_path(name: topic.name)) %></td>
|
|
32
|
+
<td><%= topic.subscriptions_count %></td>
|
|
33
|
+
<td><%= topic.last_triggered_at || "--" %></td>
|
|
34
|
+
</tr>
|
|
35
|
+
<% end %>
|
|
36
|
+
<% end %>
|
|
37
|
+
</tbody>
|
|
38
|
+
</table>
|
|
39
|
+
|
|
40
|
+
<div class="row">
|
|
41
|
+
<div class="col-auto">
|
|
42
|
+
<% if @page > 1 %>
|
|
43
|
+
<%= link_to("« prev", graphql_dashboard.subscriptions_topics_path(per_page: params[:per_page], page: @page - 1), class: "btn btn-outline-secondary") %>
|
|
44
|
+
<% else %>
|
|
45
|
+
<button class="btn btn-outline-secondary" disabled>« prev</button>
|
|
46
|
+
<% end %>
|
|
47
|
+
</div>
|
|
48
|
+
<div class="col-auto">
|
|
49
|
+
<% if @has_next_page %>
|
|
50
|
+
<%= link_to("next »", graphql_dashboard.subscriptions_topics_path(per_page: params[:per_page], page: @page + 1), class: "btn btn-outline-secondary") %>
|
|
51
|
+
<% else %>
|
|
52
|
+
<button class="btn btn-outline-secondary" disabled>next »</button>
|
|
53
|
+
<% end %>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<%= content_for(:title, "Subscriptions - #{params[:name]}") %>
|
|
2
|
+
<div class="row mt-3">
|
|
3
|
+
<div class="col">
|
|
4
|
+
<h3>Topic: <code><%= params[:name] %></code></h3>
|
|
5
|
+
</div>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<div class="row">
|
|
9
|
+
<div class="col">
|
|
10
|
+
<p>Last triggered: <%= @topic_last_triggered_at || "none" %></p>
|
|
11
|
+
<p><%= pluralize(@subscriptions_count, "Subscription") %></p>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<div class="row">
|
|
16
|
+
<div class="col">
|
|
17
|
+
<table class="table table-striped">
|
|
18
|
+
<thead>
|
|
19
|
+
<tr>
|
|
20
|
+
<th>Subscription ID</th>
|
|
21
|
+
<th>Created At</th>
|
|
22
|
+
<th>Subscribed?</th>
|
|
23
|
+
<th>Broadcast?</th>
|
|
24
|
+
<% if @show_broadcast_subscribers_count %><th>Subscribers</th><% end %>
|
|
25
|
+
</tr>
|
|
26
|
+
</thead>
|
|
27
|
+
<tbody>
|
|
28
|
+
<% @subscriptions.each do |subscription| %>
|
|
29
|
+
<tr>
|
|
30
|
+
<td><%= link_to(subscription[:id], graphql_dashboard.subscriptions_subscription_path(subscription[:id])) %></td>
|
|
31
|
+
<td><%= subscription[:created_at] %></td>
|
|
32
|
+
<td><code><%= subscription[:still_subscribed] ? "YES" : "NO" %></code></td>
|
|
33
|
+
<td><code><%= subscription[:is_broadcast] ? "YES" : "NO" %></code></td>
|
|
34
|
+
<% if @show_broadcast_subscribers_count %><td><%= subscription[:subscribers_count] %></td><% end %>
|
|
35
|
+
</tr>
|
|
36
|
+
<% end %>
|
|
37
|
+
</tbody>
|
|
38
|
+
</table>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en" class="h-100" >
|
|
3
|
+
<head>
|
|
4
|
+
<link rel="icon" type="image/png" href="<%= graphql_dashboard.static_path("icon.png") %>">
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
7
|
+
<title>GraphQL Dashboard <%= content_for?(:title) ? " · #{content_for(:title)}" : "" %> </title>
|
|
8
|
+
<link rel="stylesheet" href="<%= graphql_dashboard.static_path("bootstrap-5.3.3.min.css") %>" media="screen">
|
|
9
|
+
<link rel="stylesheet" href="<%= graphql_dashboard.static_path("charts.min.css") %>" media="screen">
|
|
10
|
+
<link rel="stylesheet" href="<%= graphql_dashboard.static_path("dashboard.css") %>" media="screen">
|
|
11
|
+
<script src="<%= graphql_dashboard.static_path("bootstrap-5.3.3.min.js") %>"></script>
|
|
12
|
+
<script src="<%= graphql_dashboard.static_path("dashboard.js") %>"></script>
|
|
13
|
+
<%= csrf_meta_tags %>
|
|
14
|
+
</head>
|
|
15
|
+
<body class="h-100 d-flex flex-column">
|
|
16
|
+
<main class="flex-shrink-0">
|
|
17
|
+
<div class="container-fluid">
|
|
18
|
+
<div class="row">
|
|
19
|
+
<div class="col gx-0">
|
|
20
|
+
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
|
21
|
+
<div class="container-fluid">
|
|
22
|
+
<%= link_to graphql_dashboard.root_path, class: "navbar-brand" do %>
|
|
23
|
+
<img id="header-icon" src="<%= graphql_dashboard.static_path("header-icon.png") %>" alt="GraphQL-Ruby">
|
|
24
|
+
<% end %>
|
|
25
|
+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
|
26
|
+
<span class="navbar-toggler-icon"></span>
|
|
27
|
+
</button>
|
|
28
|
+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
|
29
|
+
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
|
30
|
+
<li class="nav-item">
|
|
31
|
+
<%= link_to "Traces", graphql_dashboard.detailed_traces_traces_path, class: "nav-link #{params[:controller] == "graphql/dashboard/detailed_traces" ? "active" : ""}" %>
|
|
32
|
+
</li>
|
|
33
|
+
<li class="nav-item dropdown">
|
|
34
|
+
<a class="nav-link dropdown-toggle <%= params[:controller].include?("operation_store") ? "active" : "" %>" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
|
35
|
+
Persisted Operations
|
|
36
|
+
</a>
|
|
37
|
+
<ul class="dropdown-menu">
|
|
38
|
+
<li>
|
|
39
|
+
<%= link_to "Clients", graphql_dashboard.operation_store_clients_path, class: "dropdown-item" %>
|
|
40
|
+
</li>
|
|
41
|
+
<li>
|
|
42
|
+
<%= link_to "Operations", graphql_dashboard.operation_store_operations_path, class: "dropdown-item" %>
|
|
43
|
+
</li>
|
|
44
|
+
<li>
|
|
45
|
+
<%= link_to "Index", graphql_dashboard.operation_store_index_entries_path, class: "dropdown-item" %>
|
|
46
|
+
</li>
|
|
47
|
+
</ul>
|
|
48
|
+
</li>
|
|
49
|
+
<li class="nav-item">
|
|
50
|
+
<%= link_to "Subscriptions", graphql_dashboard.subscriptions_topics_path, class: "nav-link #{params[:controller] == "graphql/dashboard/subscriptions" ? "active" : ""}" %>
|
|
51
|
+
</li>
|
|
52
|
+
<li class="nav-item dropdown">
|
|
53
|
+
<a class="nav-link dropdown-toggle <%= params[:controller].include?("limiters") ? "active" : "" %>" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
|
54
|
+
Rate Limiters
|
|
55
|
+
</a>
|
|
56
|
+
<ul class="dropdown-menu">
|
|
57
|
+
<li>
|
|
58
|
+
<%= link_to "Runtime", graphql_dashboard.limiters_limiter_path("runtime", chart: params[:chart]), class: "dropdown-item" %>
|
|
59
|
+
</li>
|
|
60
|
+
<li>
|
|
61
|
+
<%= link_to "Active Operations", graphql_dashboard.limiters_limiter_path("active_operations", chart: params[:chart]), class: "dropdown-item" %>
|
|
62
|
+
</li>
|
|
63
|
+
<% if schema_class.respond_to?(:enterprise_mutation_limiter) && schema_class.enterprise_mutation_limiter %>
|
|
64
|
+
<li>
|
|
65
|
+
<%= link_to "Mutations", graphql_dashboard.limiters_limiter_path("mutations", chart: params[:chart]), class: "dropdown-item" %>
|
|
66
|
+
</li>
|
|
67
|
+
<% end %>
|
|
68
|
+
</ul>
|
|
69
|
+
</li>
|
|
70
|
+
</ul>
|
|
71
|
+
<span class="navbar-text pe-2">
|
|
72
|
+
<%= link_to ".", "#", class: "nav-link", id: "themeToggle" %>
|
|
73
|
+
</span>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</nav>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
<% flash.each do |flash_type, flash_message| %>
|
|
80
|
+
<div class="row mt-2">
|
|
81
|
+
<div class="col">
|
|
82
|
+
<div class="alert alert-<%= flash_type %> alert-dismissible fade show" role="alert">
|
|
83
|
+
<%= flash_message %>
|
|
84
|
+
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
<% end %>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="container-fluid">
|
|
91
|
+
<%= yield %>
|
|
92
|
+
</div>
|
|
93
|
+
</main>
|
|
94
|
+
<footer class="mt-auto">
|
|
95
|
+
<div class="container-fluid">
|
|
96
|
+
<div class="sticky-bottom">
|
|
97
|
+
<div class="row bg-body-tertiary">
|
|
98
|
+
<div class="col gx-0 px-4">
|
|
99
|
+
<p class="fs-6 text-center pt-2 text-muted">
|
|
100
|
+
<em>GraphQL-Ruby v<%= GraphQL::VERSION %></em> · <code><%= schema_class %></code>
|
|
101
|
+
</p>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</footer>
|
|
107
|
+
</body>
|
|
108
|
+
</html>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'rails/engine'
|
|
3
|
+
require 'action_controller'
|
|
4
|
+
module Graphql
|
|
5
|
+
# `GraphQL::Dashboard` is a `Rails::Engine`-based dashboard for viewing metadata about your GraphQL schema.
|
|
6
|
+
#
|
|
7
|
+
# Pass the class name of your schema when mounting it.
|
|
8
|
+
# @see GraphQL::Tracing::DetailedTrace DetailedTrace for viewing production traces in the Dashboard
|
|
9
|
+
#
|
|
10
|
+
# @example Mounting the Dashboard in your app
|
|
11
|
+
# mount GraphQL::Dashboard, at: "graphql_dashboard", schema: "MySchema"
|
|
12
|
+
#
|
|
13
|
+
# @example Authenticating the Dashboard with HTTP Basic Auth
|
|
14
|
+
# # config/initializers/graphql_dashboard.rb
|
|
15
|
+
# GraphQL::Dashboard.middleware.use(Rack::Auth::Basic) do |username, password|
|
|
16
|
+
# # Compare the provided username/password to an application setting:
|
|
17
|
+
# ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.graphql_dashboard_username, username) &&
|
|
18
|
+
# ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.graphql_dashboard_username, password)
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# @example Custom Rails authentication
|
|
22
|
+
# # config/initializers/graphql_dashboard.rb
|
|
23
|
+
# ActiveSupport.on_load(:graphql_dashboard_application_controller) do
|
|
24
|
+
# # context here is GraphQL::Dashboard::ApplicationController
|
|
25
|
+
#
|
|
26
|
+
# before_action do
|
|
27
|
+
# raise ActionController::RoutingError.new('Not Found') unless current_user&.admin?
|
|
28
|
+
# end
|
|
29
|
+
#
|
|
30
|
+
# def current_user
|
|
31
|
+
# # load current user
|
|
32
|
+
# end
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
class Dashboard < Rails::Engine
|
|
36
|
+
engine_name "graphql_dashboard"
|
|
37
|
+
isolate_namespace(Graphql::Dashboard)
|
|
38
|
+
|
|
39
|
+
autoload :ApplicationController, "graphql/dashboard/application_controller"
|
|
40
|
+
autoload :LandingsController, "graphql/dashboard/landings_controller"
|
|
41
|
+
autoload :StaticsController, "graphql/dashboard/statics_controller"
|
|
42
|
+
autoload :DetailedTraces, "graphql/dashboard/detailed_traces"
|
|
43
|
+
autoload :Subscriptions, "graphql/dashboard/subscriptions"
|
|
44
|
+
autoload :OperationStore, "graphql/dashboard/operation_store"
|
|
45
|
+
autoload :Limiters, "graphql/dashboard/limiters"
|
|
46
|
+
|
|
47
|
+
routes do
|
|
48
|
+
root "landings#show"
|
|
49
|
+
resources :statics, only: :show, constraints: { id: /[0-9A-Za-z\-.]+/ }
|
|
50
|
+
|
|
51
|
+
namespace :detailed_traces do
|
|
52
|
+
resources :traces, only: [:index, :show, :destroy] do
|
|
53
|
+
collection do
|
|
54
|
+
delete :delete_all, to: "traces#delete_all", as: :delete_all
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
namespace :limiters do
|
|
60
|
+
resources :limiters, only: [:show, :update], param: :name
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
namespace :operation_store do
|
|
64
|
+
resources :clients, param: :name do
|
|
65
|
+
resources :operations, param: :digest, only: [:index] do
|
|
66
|
+
collection do
|
|
67
|
+
get :archived, to: "operations#index", archived_status: :archived, as: :archived
|
|
68
|
+
post :archive, to: "operations#update", modification: :archive, as: :archive
|
|
69
|
+
post :unarchive, to: "operations#update", modification: :unarchive, as: :unarchive
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
resources :operations, param: :digest, only: [:index, :show] do
|
|
75
|
+
collection do
|
|
76
|
+
get :archived, to: "operations#index", archived_status: :archived, as: :archived
|
|
77
|
+
post :archive, to: "operations#update", modification: :archive, as: :archive
|
|
78
|
+
post :unarchive, to: "operations#update", modification: :unarchive, as: :unarchive
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
resources :index_entries, only: [:index, :show], param: :name, constraints: { name: /[A-Za-z0-9_.]+/}
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
namespace :subscriptions do
|
|
85
|
+
resources :topics, only: [:index, :show], param: :name, constraints: { name: /.*/ }
|
|
86
|
+
resources :subscriptions, only: [:show], constraints: { id: /[a-zA-Z0-9\-]+/ }
|
|
87
|
+
post "/subscriptions/clear_all", to: "subscriptions#clear_all", as: :clear_all
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Rails expects the engine to be called `Graphql::Dashboard`,
|
|
94
|
+
# but `GraphQL::Dashboard` is consistent with this gem's naming.
|
|
95
|
+
# So define both constants to refer to the same class.
|
|
96
|
+
GraphQL::Dashboard = Graphql::Dashboard
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require "graphql/dataloader/source"
|
|
3
|
+
require "graphql/dataloader/active_record_source"
|
|
4
|
+
|
|
5
|
+
module GraphQL
|
|
6
|
+
class Dataloader
|
|
7
|
+
class ActiveRecordAssociationSource < GraphQL::Dataloader::Source
|
|
8
|
+
RECORD_SOURCE_CLASS = ActiveRecordSource
|
|
9
|
+
|
|
10
|
+
def initialize(association, scope = nil)
|
|
11
|
+
@association = association
|
|
12
|
+
@scope = scope
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.batch_key_for(association, scope = nil)
|
|
16
|
+
if scope
|
|
17
|
+
[association, scope.to_sql]
|
|
18
|
+
else
|
|
19
|
+
[association]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def load(record)
|
|
24
|
+
if (assoc = record.association(@association)).loaded?
|
|
25
|
+
assoc.target
|
|
26
|
+
else
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def fetch(records)
|
|
32
|
+
record_classes = Set.new.compare_by_identity
|
|
33
|
+
associated_classes = Set.new.compare_by_identity
|
|
34
|
+
scoped_fetch = !@scope.nil?
|
|
35
|
+
records.each do |record|
|
|
36
|
+
if scoped_fetch
|
|
37
|
+
assoc = record.association(@association)
|
|
38
|
+
assoc.reset
|
|
39
|
+
end
|
|
40
|
+
if record_classes.add?(record.class)
|
|
41
|
+
reflection = record.class.reflect_on_association(@association)
|
|
42
|
+
if !reflection.polymorphic? && reflection.klass
|
|
43
|
+
associated_classes.add(reflection.klass)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
available_records = []
|
|
49
|
+
associated_classes.each do |assoc_class|
|
|
50
|
+
already_loaded_records = dataloader.with(RECORD_SOURCE_CLASS, assoc_class).results.values
|
|
51
|
+
available_records.concat(already_loaded_records)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
::ActiveRecord::Associations::Preloader.new(records: records, associations: @association, available_records: available_records, scope: @scope).call
|
|
55
|
+
|
|
56
|
+
loaded_associated_records = records.map { |r|
|
|
57
|
+
assoc = r.association(@association)
|
|
58
|
+
lar = assoc.target
|
|
59
|
+
if scoped_fetch
|
|
60
|
+
assoc.reset
|
|
61
|
+
end
|
|
62
|
+
lar
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if !scoped_fetch
|
|
66
|
+
# Don't cache records loaded via scope because they might have reduced `SELECT`s
|
|
67
|
+
# Could check .select_values here?
|
|
68
|
+
records_by_model = {}
|
|
69
|
+
loaded_associated_records.flatten.each do |record|
|
|
70
|
+
if record
|
|
71
|
+
updates = records_by_model[record.class] ||= {}
|
|
72
|
+
updates[record.id] = record
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
records_by_model.each do |model_class, updates|
|
|
76
|
+
dataloader.with(RECORD_SOURCE_CLASS, model_class).merge(updates)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
loaded_associated_records
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require "graphql/dataloader/source"
|
|
3
|
+
|
|
4
|
+
module GraphQL
|
|
5
|
+
class Dataloader
|
|
6
|
+
class ActiveRecordSource < GraphQL::Dataloader::Source
|
|
7
|
+
def initialize(model_class, find_by: model_class.primary_key)
|
|
8
|
+
@model_class = model_class
|
|
9
|
+
@find_by = find_by
|
|
10
|
+
@find_by_many = find_by.is_a?(Array)
|
|
11
|
+
if @find_by_many
|
|
12
|
+
@type_for_column = @find_by.map { |fb| @model_class.type_for_attribute(fb) }
|
|
13
|
+
else
|
|
14
|
+
@type_for_column = @model_class.type_for_attribute(@find_by)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def result_key_for(requested_key)
|
|
19
|
+
normalize_fetch_key(requested_key)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def normalize_fetch_key(requested_key)
|
|
23
|
+
if @find_by_many
|
|
24
|
+
requested_key.each_with_index.map do |k, idx|
|
|
25
|
+
@type_for_column[idx].cast(k)
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
@type_for_column.cast(requested_key)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def fetch(record_ids)
|
|
33
|
+
records = @model_class.where(@find_by => record_ids)
|
|
34
|
+
record_lookup = {}
|
|
35
|
+
if @find_by_many
|
|
36
|
+
records.each do |r|
|
|
37
|
+
key = @find_by.map { |fb| r.public_send(fb) }
|
|
38
|
+
record_lookup[key] = r
|
|
39
|
+
end
|
|
40
|
+
else
|
|
41
|
+
records.each { |r| record_lookup[r.public_send(@find_by)] = r }
|
|
42
|
+
end
|
|
43
|
+
record_ids.map { |id| record_lookup[id] }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module GraphQL
|
|
3
|
+
class Dataloader
|
|
4
|
+
class AsyncDataloader < Dataloader
|
|
5
|
+
def yield(source = Fiber[:__graphql_current_dataloader_source])
|
|
6
|
+
trace = Fiber[:__graphql_current_multiplex]&.current_trace
|
|
7
|
+
trace&.dataloader_fiber_yield(source)
|
|
8
|
+
if (condition = Fiber[:graphql_dataloader_next_tick])
|
|
9
|
+
condition.wait
|
|
10
|
+
else
|
|
11
|
+
Fiber.yield
|
|
12
|
+
end
|
|
13
|
+
trace&.dataloader_fiber_resume(source)
|
|
14
|
+
nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def run(trace_query_lazy: nil)
|
|
18
|
+
trace = Fiber[:__graphql_current_multiplex]&.current_trace
|
|
19
|
+
jobs_fiber_limit, total_fiber_limit = calculate_fiber_limit
|
|
20
|
+
job_fibers = []
|
|
21
|
+
next_job_fibers = []
|
|
22
|
+
source_tasks = []
|
|
23
|
+
next_source_tasks = []
|
|
24
|
+
first_pass = true
|
|
25
|
+
sources_condition = Async::Condition.new
|
|
26
|
+
manager = spawn_fiber do
|
|
27
|
+
trace&.begin_dataloader(self)
|
|
28
|
+
while first_pass || !job_fibers.empty?
|
|
29
|
+
first_pass = false
|
|
30
|
+
fiber_vars = get_fiber_variables
|
|
31
|
+
|
|
32
|
+
run_pending_steps(job_fibers, next_job_fibers, source_tasks, jobs_fiber_limit, trace)
|
|
33
|
+
|
|
34
|
+
Sync do |root_task|
|
|
35
|
+
set_fiber_variables(fiber_vars)
|
|
36
|
+
while !source_tasks.empty? || @source_cache.each_value.any? { |group_sources| group_sources.each_value.any?(&:pending?) }
|
|
37
|
+
while (task = (source_tasks.shift || (((job_fibers.size + next_job_fibers.size + source_tasks.size + next_source_tasks.size) < total_fiber_limit) && spawn_source_task(root_task, sources_condition, trace))))
|
|
38
|
+
if task.alive?
|
|
39
|
+
root_task.yield # give the source task a chance to run
|
|
40
|
+
next_source_tasks << task
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
sources_condition.signal
|
|
44
|
+
source_tasks.concat(next_source_tasks)
|
|
45
|
+
next_source_tasks.clear
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
if !@lazies_at_depth.empty?
|
|
50
|
+
with_trace_query_lazy(trace_query_lazy) do
|
|
51
|
+
run_next_pending_lazies(job_fibers, trace)
|
|
52
|
+
run_pending_steps(job_fibers, next_job_fibers, source_tasks, jobs_fiber_limit, trace)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
trace&.end_dataloader(self)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
manager.resume
|
|
60
|
+
if manager.alive?
|
|
61
|
+
raise "Invariant: Manager didn't terminate successfully: #{manager}"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
rescue UncaughtThrowError => e
|
|
65
|
+
throw e.tag, e.value
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def run_pending_steps(job_fibers, next_job_fibers, source_tasks, jobs_fiber_limit, trace)
|
|
71
|
+
while (f = (job_fibers.shift || (((job_fibers.size + next_job_fibers.size + source_tasks.size) < jobs_fiber_limit) && spawn_job_fiber(trace))))
|
|
72
|
+
if f.alive?
|
|
73
|
+
finished = run_fiber(f)
|
|
74
|
+
if !finished
|
|
75
|
+
next_job_fibers << f
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
job_fibers.concat(next_job_fibers)
|
|
80
|
+
next_job_fibers.clear
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def spawn_source_task(parent_task, condition, trace)
|
|
84
|
+
pending_sources = nil
|
|
85
|
+
@source_cache.each_value do |source_by_batch_params|
|
|
86
|
+
source_by_batch_params.each_value do |source|
|
|
87
|
+
if source.pending?
|
|
88
|
+
pending_sources ||= []
|
|
89
|
+
pending_sources << source
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
if pending_sources
|
|
95
|
+
fiber_vars = get_fiber_variables
|
|
96
|
+
parent_task.async do
|
|
97
|
+
trace&.dataloader_spawn_source_fiber(pending_sources)
|
|
98
|
+
set_fiber_variables(fiber_vars)
|
|
99
|
+
Fiber[:graphql_dataloader_next_tick] = condition
|
|
100
|
+
pending_sources.each do |s|
|
|
101
|
+
trace&.begin_dataloader_source(s)
|
|
102
|
+
s.run_pending_keys
|
|
103
|
+
trace&.end_dataloader_source(s)
|
|
104
|
+
end
|
|
105
|
+
cleanup_fiber
|
|
106
|
+
trace&.dataloader_fiber_exit
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -2,23 +2,68 @@
|
|
|
2
2
|
|
|
3
3
|
module GraphQL
|
|
4
4
|
class Dataloader
|
|
5
|
-
#
|
|
5
|
+
# GraphQL-Ruby uses this when Dataloader isn't enabled.
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
7
|
+
# It runs execution code inline and gathers lazy objects (eg. Promises)
|
|
8
|
+
# and resolves them during {#run}.
|
|
9
9
|
class NullDataloader < Dataloader
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def
|
|
10
|
+
def initialize(*)
|
|
11
|
+
@lazies_at_depth = Hash.new { |h,k| h[k] = [] }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def freeze
|
|
15
|
+
@lazies_at_depth.default_proc = nil
|
|
16
|
+
@lazies_at_depth.freeze
|
|
17
|
+
super
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def run(trace_query_lazy: nil)
|
|
21
|
+
with_trace_query_lazy(trace_query_lazy) do
|
|
22
|
+
while !@lazies_at_depth.empty?
|
|
23
|
+
smallest_depth = nil
|
|
24
|
+
@lazies_at_depth.each_key do |depth_key|
|
|
25
|
+
smallest_depth ||= depth_key
|
|
26
|
+
if depth_key < smallest_depth
|
|
27
|
+
smallest_depth = depth_key
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
if smallest_depth
|
|
32
|
+
lazies = @lazies_at_depth.delete(smallest_depth)
|
|
33
|
+
lazies.each(&:value) # resolve these Lazy instances
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def run_isolated
|
|
40
|
+
# Reuse this instance because execution code may already have a reference to _this_ `dataloader` inside the given block.
|
|
41
|
+
prev_lazies_at_depth = @lazies_at_depth
|
|
42
|
+
@lazies_at_depth = @lazies_at_depth.dup.clear
|
|
43
|
+
res = nil
|
|
44
|
+
append_job {
|
|
45
|
+
res = yield
|
|
46
|
+
}
|
|
47
|
+
run
|
|
48
|
+
res
|
|
49
|
+
ensure
|
|
50
|
+
@lazies_at_depth = prev_lazies_at_depth
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def clear_cache; end
|
|
54
|
+
|
|
55
|
+
def yield(_source)
|
|
15
56
|
raise GraphQL::Error, "GraphQL::Dataloader is not running -- add `use GraphQL::Dataloader` to your schema to use Dataloader sources."
|
|
16
57
|
end
|
|
17
58
|
|
|
18
|
-
def append_job
|
|
19
|
-
yield
|
|
59
|
+
def append_job(callable = nil)
|
|
60
|
+
callable ? callable.call : yield
|
|
20
61
|
nil
|
|
21
62
|
end
|
|
63
|
+
|
|
64
|
+
def with(*)
|
|
65
|
+
raise GraphQL::Error, "GraphQL::Dataloader is not running -- add `use GraphQL::Dataloader` to your schema to use Dataloader sources."
|
|
66
|
+
end
|
|
22
67
|
end
|
|
23
68
|
end
|
|
24
69
|
end
|
|
@@ -14,6 +14,11 @@ module GraphQL
|
|
|
14
14
|
def load
|
|
15
15
|
@source.load(@key)
|
|
16
16
|
end
|
|
17
|
+
|
|
18
|
+
def load_with_deprecation_warning
|
|
19
|
+
warn("Returning `.request(...)` from GraphQL::Dataloader is deprecated, use `.load(...)` instead. (See usage of #{@source} with #{@key.inspect}).")
|
|
20
|
+
load
|
|
21
|
+
end
|
|
17
22
|
end
|
|
18
23
|
end
|
|
19
24
|
end
|