graphql 2.2.17 → 2.5.16
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/install/mutation_root_generator.rb +2 -2
- data/lib/generators/graphql/install_generator.rb +46 -0
- data/lib/generators/graphql/orm_mutations_base.rb +1 -1
- data/lib/generators/graphql/templates/base_resolver.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +3 -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/{ast/query_depth.rb → query_depth.rb} +23 -25
- 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/current.rb +57 -0
- data/lib/graphql/dashboard/detailed_traces.rb +47 -0
- data/lib/graphql/dashboard/installable.rb +22 -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/subscriptions.rb +96 -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 +23 -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 +158 -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 +46 -19
- data/lib/graphql/dataloader/null_dataloader.rb +51 -10
- data/lib/graphql/dataloader/source.rb +20 -9
- data/lib/graphql/dataloader.rb +153 -45
- data/lib/graphql/date_encoding_error.rb +1 -1
- data/lib/graphql/dig.rb +2 -1
- 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 +63 -5
- data/lib/graphql/execution/interpreter/runtime.rb +321 -222
- data/lib/graphql/execution/interpreter.rb +23 -30
- data/lib/graphql/execution/lookahead.rb +18 -11
- data/lib/graphql/execution/multiplex.rb +6 -5
- data/lib/graphql/introspection/directive_location_enum.rb +1 -1
- data/lib/graphql/introspection/directive_type.rb +1 -1
- data/lib/graphql/introspection/entry_points.rb +2 -2
- data/lib/graphql/introspection/field_type.rb +1 -1
- data/lib/graphql/introspection/schema_type.rb +6 -11
- data/lib/graphql/introspection/type_type.rb +5 -5
- data/lib/graphql/invalid_name_error.rb +1 -1
- data/lib/graphql/invalid_null_error.rb +20 -17
- data/lib/graphql/language/cache.rb +13 -0
- data/lib/graphql/language/comment.rb +18 -0
- data/lib/graphql/language/document_from_schema_definition.rb +64 -35
- data/lib/graphql/language/lexer.rb +72 -42
- data/lib/graphql/language/nodes.rb +93 -52
- data/lib/graphql/language/parser.rb +168 -61
- data/lib/graphql/language/printer.rb +31 -15
- data/lib/graphql/language/sanitized_printer.rb +1 -1
- data/lib/graphql/language.rb +61 -1
- data/lib/graphql/pagination/connection.rb +1 -1
- data/lib/graphql/query/context/scoped_context.rb +1 -1
- data/lib/graphql/query/context.rb +46 -47
- data/lib/graphql/query/null_context.rb +3 -5
- data/lib/graphql/query/partial.rb +179 -0
- data/lib/graphql/query/validation_pipeline.rb +2 -2
- data/lib/graphql/query/variable_validation_error.rb +1 -1
- data/lib/graphql/query.rb +123 -69
- data/lib/graphql/railtie.rb +7 -0
- 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 +57 -8
- data/lib/graphql/schema/build_from_definition.rb +116 -49
- data/lib/graphql/schema/directive/flagged.rb +4 -2
- data/lib/graphql/schema/directive.rb +54 -2
- data/lib/graphql/schema/enum.rb +107 -24
- data/lib/graphql/schema/enum_value.rb +10 -2
- data/lib/graphql/schema/field/connection_extension.rb +1 -1
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +134 -45
- data/lib/graphql/schema/field_extension.rb +1 -1
- data/lib/graphql/schema/has_single_input_argument.rb +6 -2
- data/lib/graphql/schema/input_object.rb +122 -64
- data/lib/graphql/schema/interface.rb +23 -5
- data/lib/graphql/schema/introspection_system.rb +6 -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 -2
- data/lib/graphql/schema/member/base_dsl_methods.rb +15 -0
- data/lib/graphql/schema/member/has_arguments.rb +44 -58
- data/lib/graphql/schema/member/has_dataloader.rb +62 -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 +26 -6
- data/lib/graphql/schema/member/has_interfaces.rb +6 -6
- 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/type_system_helpers.rb +17 -4
- data/lib/graphql/schema/member.rb +1 -0
- data/lib/graphql/schema/mutation.rb +7 -0
- data/lib/graphql/schema/object.rb +25 -8
- data/lib/graphql/schema/printer.rb +1 -0
- data/lib/graphql/schema/ractor_shareable.rb +79 -0
- data/lib/graphql/schema/relay_classic_mutation.rb +0 -1
- data/lib/graphql/schema/resolver.rb +29 -23
- data/lib/graphql/schema/scalar.rb +1 -6
- data/lib/graphql/schema/subscription.rb +52 -6
- data/lib/graphql/schema/timeout.rb +19 -2
- data/lib/graphql/schema/type_expression.rb +2 -2
- data/lib/graphql/schema/union.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 +190 -20
- data/lib/graphql/schema.rb +695 -167
- data/lib/graphql/static_validation/all_rules.rb +2 -2
- data/lib/graphql/static_validation/base_visitor.rb +6 -5
- data/lib/graphql/static_validation/literal_validator.rb +4 -4
- 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 +4 -4
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +3 -3
- 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 +18 -2
- data/lib/graphql/static_validation/validator.rb +6 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +5 -3
- 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 +13 -2
- data/lib/graphql/subscriptions/serialize.rb +1 -1
- data/lib/graphql/subscriptions.rb +7 -5
- data/lib/graphql/testing/helpers.rb +48 -16
- data/lib/graphql/testing/mock_action_cable.rb +111 -0
- data/lib/graphql/testing.rb +1 -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 +5 -1
- data/lib/graphql/tracing/appoptics_tracing.rb +7 -0
- 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/memory_backend.rb +60 -0
- data/lib/graphql/tracing/detailed_trace/redis_backend.rb +72 -0
- data/lib/graphql/tracing/detailed_trace.rb +141 -0
- data/lib/graphql/tracing/legacy_hooks_trace.rb +1 -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 +818 -0
- data/lib/graphql/tracing/platform_tracing.rb +1 -1
- data/lib/graphql/tracing/prometheus_trace/graphql_collector.rb +2 -0
- 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 +64 -98
- data/lib/graphql/tracing/statsd_trace.rb +33 -45
- data/lib/graphql/tracing/statsd_tracing.rb +2 -0
- data/lib/graphql/tracing/trace.rb +111 -1
- data/lib/graphql/tracing.rb +31 -30
- data/lib/graphql/type_kinds.rb +2 -1
- data/lib/graphql/types/relay/connection_behaviors.rb +12 -2
- data/lib/graphql/types/relay/edge_behaviors.rb +11 -1
- data/lib/graphql/types/relay/page_info_behaviors.rb +4 -0
- data/lib/graphql/types.rb +18 -11
- data/lib/graphql/unauthorized_enum_value_error.rb +13 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +64 -54
- metadata +197 -22
- data/lib/graphql/analysis/ast/analyzer.rb +0 -91
- data/lib/graphql/analysis/ast/field_usage.rb +0 -82
- 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 -182
- data/lib/graphql/analysis/ast/visitor.rb +0 -276
- data/lib/graphql/analysis/ast.rb +0 -94
- data/lib/graphql/backtrace/inspect_result.rb +0 -50
- data/lib/graphql/backtrace/trace.rb +0 -93
- data/lib/graphql/backtrace/tracer.rb +0 -80
- data/lib/graphql/language/token.rb +0 -34
- 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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative "./installable"
|
|
3
|
+
module Graphql
|
|
4
|
+
class Dashboard < Rails::Engine
|
|
5
|
+
module DetailedTraces
|
|
6
|
+
class TracesController < Graphql::Dashboard::ApplicationController
|
|
7
|
+
include Installable
|
|
8
|
+
|
|
9
|
+
def index
|
|
10
|
+
@last = params[:last]&.to_i || 50
|
|
11
|
+
@before = params[:before]&.to_i
|
|
12
|
+
@traces = schema_class.detailed_trace.traces(last: @last, before: @before)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def show
|
|
16
|
+
trace = schema_class.detailed_trace.find_trace(params[:id].to_i)
|
|
17
|
+
send_data(trace.trace_data)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def destroy
|
|
21
|
+
schema_class.detailed_trace.delete_trace(params[:id])
|
|
22
|
+
flash[:success] = "Trace deleted."
|
|
23
|
+
head :no_content
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def delete_all
|
|
27
|
+
schema_class.detailed_trace.delete_all_traces
|
|
28
|
+
flash[:success] = "Deleted all traces."
|
|
29
|
+
head :no_content
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def feature_installed?
|
|
35
|
+
!!schema_class.detailed_trace
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
INSTALLABLE_COMPONENT_HEADER_HTML = "Detailed traces aren't installed yet."
|
|
39
|
+
INSTALLABLE_COMPONENT_MESSAGE_HTML = <<~HTML.html_safe
|
|
40
|
+
GraphQL-Ruby can instrument production traffic and save tracing artifacts here for later review.
|
|
41
|
+
<br>
|
|
42
|
+
Read more in <a href="https://graphql-ruby.org/queries/tracing#detailed-traces">the detailed tracing docs</a>.
|
|
43
|
+
HTML
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Graphql
|
|
3
|
+
class Dashboard < Rails::Engine
|
|
4
|
+
module Installable
|
|
5
|
+
def self.included(child_module)
|
|
6
|
+
child_module.before_action(:check_installed)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def feature_installed?
|
|
10
|
+
raise "Implement #{self.class}#feature_installed? to check whether this should render `not_installed` or not."
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def check_installed
|
|
14
|
+
if !feature_installed?
|
|
15
|
+
@component_header_html = self.class::INSTALLABLE_COMPONENT_HEADER_HTML
|
|
16
|
+
@component_message_html = self.class::INSTALLABLE_COMPONENT_MESSAGE_HTML
|
|
17
|
+
render "graphql/dashboard/not_installed"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative "./installable"
|
|
3
|
+
module Graphql
|
|
4
|
+
class Dashboard < Rails::Engine
|
|
5
|
+
module Limiters
|
|
6
|
+
class LimitersController < Dashboard::ApplicationController
|
|
7
|
+
include Installable
|
|
8
|
+
FALLBACK_CSP_NONCE_GENERATOR = ->(_req) { SecureRandom.hex(32) }
|
|
9
|
+
|
|
10
|
+
def show
|
|
11
|
+
name = params[:name]
|
|
12
|
+
@title = case name
|
|
13
|
+
when "runtime"
|
|
14
|
+
"Runtime Limiter"
|
|
15
|
+
when "active_operations"
|
|
16
|
+
"Active Operation Limiter"
|
|
17
|
+
when "mutations"
|
|
18
|
+
"Mutation Limiter"
|
|
19
|
+
else
|
|
20
|
+
raise ArgumentError, "Unknown limiter name: #{name}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
limiter = limiter_for(name)
|
|
24
|
+
if limiter.nil?
|
|
25
|
+
@install_path = "http://graphql-ruby.org/limiters/#{name}"
|
|
26
|
+
else
|
|
27
|
+
@chart_mode = params[:chart] || "day"
|
|
28
|
+
@current_soft = limiter.soft_limit_enabled?
|
|
29
|
+
@histogram = limiter.dashboard_histogram(@chart_mode)
|
|
30
|
+
|
|
31
|
+
# These configs may have already been defined by the application; provide overrides here if not.
|
|
32
|
+
request.content_security_policy_nonce_generator ||= FALLBACK_CSP_NONCE_GENERATOR
|
|
33
|
+
nonce_dirs = request.content_security_policy_nonce_directives || []
|
|
34
|
+
if !nonce_dirs.include?("style-src")
|
|
35
|
+
nonce_dirs += ["style-src"]
|
|
36
|
+
request.content_security_policy_nonce_directives = nonce_dirs
|
|
37
|
+
end
|
|
38
|
+
@csp_nonce = request.content_security_policy_nonce
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def update
|
|
43
|
+
name = params[:name]
|
|
44
|
+
limiter = limiter_for(name)
|
|
45
|
+
if limiter
|
|
46
|
+
limiter.toggle_soft_limit
|
|
47
|
+
flash[:success] = if limiter.soft_limit_enabled?
|
|
48
|
+
"Enabled soft limiting -- over-limit traffic will be logged but not rejected."
|
|
49
|
+
else
|
|
50
|
+
"Disabled soft limiting -- over-limit traffic will be rejected."
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
flash[:warning] = "No limiter configured for #{name.inspect}"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
redirect_to graphql_dashboard.limiters_limiter_path(name, chart: params[:chart])
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def limiter_for(name)
|
|
62
|
+
case name
|
|
63
|
+
when "runtime"
|
|
64
|
+
schema_class.enterprise_runtime_limiter
|
|
65
|
+
when "active_operations"
|
|
66
|
+
schema_class.enterprise_active_operation_limiter
|
|
67
|
+
when "mutations"
|
|
68
|
+
schema_class.enterprise_mutation_limiter
|
|
69
|
+
else
|
|
70
|
+
raise ArgumentError, "Unknown limiter: #{name}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def feature_installed?
|
|
75
|
+
defined?(GraphQL::Enterprise::Limiter) &&
|
|
76
|
+
(
|
|
77
|
+
schema_class.enterprise_active_operation_limiter ||
|
|
78
|
+
schema_class.enterprise_runtime_limiter ||
|
|
79
|
+
(schema_class.respond_to?(:enterprise_mutation_limiter) && schema_class.enterprise_mutation_limiter)
|
|
80
|
+
)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
INSTALLABLE_COMPONENT_HEADER_HTML = "Rate limiters aren't installed on this schema yet."
|
|
85
|
+
INSTALLABLE_COMPONENT_MESSAGE_HTML = <<-HTML.html_safe
|
|
86
|
+
Check out the docs to get started with GraphQL-Enterprise's
|
|
87
|
+
<a href="https://graphql-ruby.org/limiters/runtime.html">runtime limiter</a> or
|
|
88
|
+
<a href="https://graphql-ruby.org/limiters/active_operations.html">active operation limiter</a>.
|
|
89
|
+
HTML
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative "./installable"
|
|
3
|
+
module Graphql
|
|
4
|
+
class Dashboard < Rails::Engine
|
|
5
|
+
module OperationStore
|
|
6
|
+
class BaseController < Dashboard::ApplicationController
|
|
7
|
+
include Installable
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def feature_installed?
|
|
12
|
+
schema_class.respond_to?(:operation_store) && schema_class.operation_store.is_a?(GraphQL::Pro::OperationStore)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
INSTALLABLE_COMPONENT_HEADER_HTML = "<code>OperationStore</code> isn't installed for this schema yet.".html_safe
|
|
16
|
+
INSTALLABLE_COMPONENT_MESSAGE_HTML = <<-HTML.html_safe
|
|
17
|
+
Learn more about improving performance and security with stored operations
|
|
18
|
+
in the <a href="https://graphql-ruby.org/operation_store/overview.html"><code>OperationStore</code> docs</a>.
|
|
19
|
+
HTML
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class ClientsController < BaseController
|
|
23
|
+
def index
|
|
24
|
+
@order_by = params[:order_by] || "name"
|
|
25
|
+
@order_dir = params[:order_dir].presence || "asc"
|
|
26
|
+
clients_page = schema_class.operation_store.all_clients(
|
|
27
|
+
page: params[:page]&.to_i || 1,
|
|
28
|
+
per_page: params[:per_page]&.to_i || 25,
|
|
29
|
+
order_by: @order_by,
|
|
30
|
+
order_dir: @order_dir,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
@clients_page = clients_page
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def new
|
|
37
|
+
@client = init_client(secret: SecureRandom.hex(32))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def create
|
|
41
|
+
client_params = params.require(:client).permit(:name, :secret)
|
|
42
|
+
schema_class.operation_store.upsert_client(client_params[:name], client_params[:secret])
|
|
43
|
+
flash[:success] = "Created #{client_params[:name].inspect}"
|
|
44
|
+
redirect_to graphql_dashboard.operation_store_clients_path
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def edit
|
|
48
|
+
@client = schema_class.operation_store.get_client(params[:name])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def update
|
|
52
|
+
client_name = params[:name]
|
|
53
|
+
client_secret = params.require(:client).permit(:secret)[:secret]
|
|
54
|
+
schema_class.operation_store.upsert_client(client_name, client_secret)
|
|
55
|
+
flash[:success] = "Updated #{client_name.inspect}"
|
|
56
|
+
redirect_to graphql_dashboard.operation_store_clients_path
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def destroy
|
|
60
|
+
client_name = params[:name]
|
|
61
|
+
schema_class.operation_store.delete_client(client_name)
|
|
62
|
+
flash[:success] = "Deleted #{client_name.inspect}"
|
|
63
|
+
redirect_to graphql_dashboard.operation_store_clients_path
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def init_client(name: nil, secret: nil)
|
|
69
|
+
GraphQL::Pro::OperationStore::ClientRecord.new(
|
|
70
|
+
name: name,
|
|
71
|
+
secret: secret,
|
|
72
|
+
created_at: nil,
|
|
73
|
+
operations_count: 0,
|
|
74
|
+
archived_operations_count: 0,
|
|
75
|
+
last_synced_at: nil,
|
|
76
|
+
last_used_at: nil,
|
|
77
|
+
)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class OperationsController < BaseController
|
|
82
|
+
def index
|
|
83
|
+
@client_operations = client_name = params[:client_name]
|
|
84
|
+
per_page = params[:per_page]&.to_i || 25
|
|
85
|
+
page = params[:page]&.to_i || 1
|
|
86
|
+
@is_archived = params[:archived_status] == :archived
|
|
87
|
+
order_by = params[:order_by] || "name"
|
|
88
|
+
order_dir = params[:order_dir]&.to_sym || :asc
|
|
89
|
+
if @client_operations
|
|
90
|
+
@operations_page = schema_class.operation_store.get_client_operations_by_client(
|
|
91
|
+
client_name,
|
|
92
|
+
page: page,
|
|
93
|
+
per_page: per_page,
|
|
94
|
+
is_archived: @is_archived,
|
|
95
|
+
order_by: order_by,
|
|
96
|
+
order_dir: order_dir,
|
|
97
|
+
)
|
|
98
|
+
opposite_archive_mode_count = schema_class.operation_store.get_client_operations_by_client(
|
|
99
|
+
client_name,
|
|
100
|
+
page: 1,
|
|
101
|
+
per_page: 1,
|
|
102
|
+
is_archived: !@is_archived,
|
|
103
|
+
order_by: order_by,
|
|
104
|
+
order_dir: order_dir,
|
|
105
|
+
).total_count
|
|
106
|
+
else
|
|
107
|
+
@operations_page = schema_class.operation_store.all_operations(
|
|
108
|
+
page: page,
|
|
109
|
+
per_page: per_page,
|
|
110
|
+
is_archived: @is_archived,
|
|
111
|
+
order_by: order_by,
|
|
112
|
+
order_dir: order_dir,
|
|
113
|
+
)
|
|
114
|
+
opposite_archive_mode_count = schema_class.operation_store.all_operations(
|
|
115
|
+
page: 1,
|
|
116
|
+
per_page: 1,
|
|
117
|
+
is_archived: !@is_archived,
|
|
118
|
+
order_by: order_by,
|
|
119
|
+
order_dir: order_dir,
|
|
120
|
+
).total_count
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
if @is_archived
|
|
124
|
+
@archived_operations_count = @operations_page.total_count
|
|
125
|
+
@unarchived_operations_count = opposite_archive_mode_count
|
|
126
|
+
else
|
|
127
|
+
@archived_operations_count = opposite_archive_mode_count
|
|
128
|
+
@unarchived_operations_count = @operations_page.total_count
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def show
|
|
133
|
+
digest = params[:digest]
|
|
134
|
+
@operation = schema_class.operation_store.get_operation_by_digest(digest)
|
|
135
|
+
if @operation
|
|
136
|
+
# Parse & re-format the query
|
|
137
|
+
document = GraphQL.parse(@operation.body)
|
|
138
|
+
@graphql_source = document.to_query_string
|
|
139
|
+
|
|
140
|
+
@client_operations = schema_class.operation_store.get_client_operations_by_digest(digest)
|
|
141
|
+
@entries = schema_class.operation_store.get_index_entries_by_digest(digest)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def update
|
|
146
|
+
is_archived = case params[:modification]
|
|
147
|
+
when :archive
|
|
148
|
+
true
|
|
149
|
+
when :unarchive
|
|
150
|
+
false
|
|
151
|
+
else
|
|
152
|
+
raise ArgumentError, "Unexpected modification: #{params[:modification].inspect}"
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
if (client_name = params[:client_name])
|
|
156
|
+
operation_aliases = params[:operation_aliases]
|
|
157
|
+
schema_class.operation_store.archive_client_operations(
|
|
158
|
+
client_name: client_name,
|
|
159
|
+
operation_aliases: operation_aliases,
|
|
160
|
+
is_archived: is_archived
|
|
161
|
+
)
|
|
162
|
+
flash[:success] = "#{is_archived ? "Archived" : "Activated"} #{operation_aliases.size} #{"operation".pluralize(operation_aliases.size)}"
|
|
163
|
+
else
|
|
164
|
+
digests = params[:digests]
|
|
165
|
+
schema_class.operation_store.archive_operations(
|
|
166
|
+
digests: digests,
|
|
167
|
+
is_archived: is_archived
|
|
168
|
+
)
|
|
169
|
+
flash[:success] = "#{is_archived ? "Archived" : "Activated"} #{digests.size} #{"operation".pluralize(digests.size)}"
|
|
170
|
+
end
|
|
171
|
+
head :no_content
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
class IndexEntriesController < BaseController
|
|
176
|
+
def index
|
|
177
|
+
@search_term = if request.params["q"] && request.params["q"].length > 0
|
|
178
|
+
request.params["q"]
|
|
179
|
+
else
|
|
180
|
+
nil
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
@index_entries_page = schema_class.operation_store.all_index_entries(
|
|
184
|
+
search_term: @search_term,
|
|
185
|
+
page: params[:page]&.to_i || 1,
|
|
186
|
+
per_page: params[:per_page]&.to_i || 25,
|
|
187
|
+
)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def show
|
|
191
|
+
name = params[:name]
|
|
192
|
+
@entry = schema_class.operation_store.index.get_entry(name)
|
|
193
|
+
@chain = schema_class.operation_store.index.index_entry_chain(name)
|
|
194
|
+
@operations = schema_class.operation_store.get_operations_by_index_entry(name)
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|