graphql 2.4.5 → 2.5.21
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/templates/create_graphql_detailed_traces.erb +10 -0
- data/lib/graphql/analysis/analyzer.rb +2 -1
- data/lib/graphql/analysis/query_complexity.rb +87 -7
- data/lib/graphql/analysis/visitor.rb +37 -40
- data/lib/graphql/analysis.rb +12 -9
- data/lib/graphql/autoload.rb +1 -0
- data/lib/graphql/backtrace/table.rb +118 -55
- data/lib/graphql/backtrace.rb +1 -19
- data/lib/graphql/current.rb +6 -1
- 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 +38 -15
- data/lib/graphql/dataloader/null_dataloader.rb +55 -10
- data/lib/graphql/dataloader/source.rb +18 -6
- data/lib/graphql/dataloader.rb +110 -26
- data/lib/graphql/date_encoding_error.rb +1 -1
- data/lib/graphql/dig.rb +2 -1
- data/lib/graphql/execution/interpreter/resolve.rb +10 -16
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +58 -5
- data/lib/graphql/execution/interpreter/runtime.rb +229 -93
- data/lib/graphql/execution/interpreter.rb +15 -24
- data/lib/graphql/execution/multiplex.rb +7 -6
- data/lib/graphql/execution/next/field_resolve_step.rb +690 -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 +69 -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 +11 -3
- 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/type_type.rb +64 -28
- data/lib/graphql/invalid_name_error.rb +1 -1
- data/lib/graphql/invalid_null_error.rb +25 -16
- data/lib/graphql/language/document_from_schema_definition.rb +2 -1
- data/lib/graphql/language/lexer.rb +16 -5
- data/lib/graphql/language/nodes.rb +8 -1
- data/lib/graphql/language/parser.rb +16 -8
- data/lib/graphql/language/static_visitor.rb +37 -33
- data/lib/graphql/language/visitor.rb +59 -55
- data/lib/graphql/language.rb +21 -12
- data/lib/graphql/pagination/connection.rb +2 -0
- data/lib/graphql/pagination/connections.rb +32 -0
- data/lib/graphql/query/context.rb +6 -10
- data/lib/graphql/query/null_context.rb +9 -3
- data/lib/graphql/query/partial.rb +179 -0
- data/lib/graphql/query.rb +64 -64
- data/lib/graphql/railtie.rb +1 -1
- data/lib/graphql/schema/addition.rb +3 -1
- data/lib/graphql/schema/always_visible.rb +1 -0
- data/lib/graphql/schema/argument.rb +24 -8
- data/lib/graphql/schema/build_from_definition.rb +113 -54
- data/lib/graphql/schema/directive/flagged.rb +2 -0
- data/lib/graphql/schema/directive.rb +52 -2
- data/lib/graphql/schema/enum.rb +36 -1
- data/lib/graphql/schema/enum_value.rb +1 -1
- data/lib/graphql/schema/field/connection_extension.rb +15 -35
- data/lib/graphql/schema/field/scope_extension.rb +22 -13
- data/lib/graphql/schema/field.rb +101 -51
- data/lib/graphql/schema/field_extension.rb +33 -0
- data/lib/graphql/schema/input_object.rb +45 -38
- data/lib/graphql/schema/interface.rb +2 -1
- data/lib/graphql/schema/list.rb +1 -1
- data/lib/graphql/schema/member/base_dsl_methods.rb +1 -1
- data/lib/graphql/schema/member/has_arguments.rb +56 -19
- data/lib/graphql/schema/member/has_authorization.rb +35 -0
- data/lib/graphql/schema/member/has_dataloader.rb +79 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +15 -0
- data/lib/graphql/schema/member/has_directives.rb +1 -1
- data/lib/graphql/schema/member/has_fields.rb +81 -5
- data/lib/graphql/schema/member/has_interfaces.rb +3 -3
- data/lib/graphql/schema/member/scoped.rb +1 -1
- data/lib/graphql/schema/member/type_system_helpers.rb +17 -3
- data/lib/graphql/schema/member.rb +6 -0
- data/lib/graphql/schema/object.rb +18 -8
- data/lib/graphql/schema/ractor_shareable.rb +79 -0
- data/lib/graphql/schema/resolver.rb +52 -6
- data/lib/graphql/schema/scalar.rb +1 -6
- data/lib/graphql/schema/subscription.rb +50 -4
- data/lib/graphql/schema/timeout.rb +19 -2
- data/lib/graphql/schema/validator/required_validator.rb +71 -14
- data/lib/graphql/schema/visibility/migration.rb +3 -2
- data/lib/graphql/schema/visibility/profile.rb +115 -23
- data/lib/graphql/schema/visibility.rb +49 -32
- data/lib/graphql/schema/warden.rb +23 -2
- data/lib/graphql/schema.rb +333 -68
- data/lib/graphql/static_validation/all_rules.rb +2 -2
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +47 -13
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +79 -17
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +10 -2
- data/lib/graphql/static_validation/rules/not_single_subscription_error.rb +25 -0
- 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 +6 -2
- data/lib/graphql/static_validation/validator.rb +6 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +1 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +12 -10
- data/lib/graphql/subscriptions/event.rb +12 -1
- data/lib/graphql/subscriptions/serialize.rb +1 -1
- data/lib/graphql/subscriptions.rb +1 -1
- data/lib/graphql/testing/helpers.rb +17 -11
- 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 +9 -1
- data/lib/graphql/tracing/appoptics_tracing.rb +7 -0
- data/lib/graphql/tracing/appsignal_trace.rb +32 -55
- 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 -158
- 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 +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 +184 -34
- 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_trace.rb +5 -0
- data/lib/graphql/tracing/prometheus_trace/graphql_collector.rb +2 -0
- data/lib/graphql/tracing/prometheus_trace.rb +72 -68
- data/lib/graphql/tracing/prometheus_tracing.rb +2 -0
- data/lib/graphql/tracing/scout_trace.rb +32 -55
- data/lib/graphql/tracing/scout_tracing.rb +2 -0
- data/lib/graphql/tracing/sentry_trace.rb +64 -94
- data/lib/graphql/tracing/statsd_trace.rb +33 -41
- 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 +1 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +9 -7
- data/lib/graphql/types/relay/edge_behaviors.rb +5 -4
- 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/unauthorized_error.rb +5 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +12 -31
- metadata +174 -11
- data/lib/graphql/backtrace/inspect_result.rb +0 -38
- data/lib/graphql/backtrace/trace.rb +0 -93
- data/lib/graphql/backtrace/tracer.rb +0 -80
- data/lib/graphql/schema/null_mask.rb +0 -11
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +0 -17
data/lib/graphql/backtrace.rb
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
require "graphql/backtrace/inspect_result"
|
|
3
2
|
require "graphql/backtrace/table"
|
|
4
3
|
require "graphql/backtrace/traced_error"
|
|
5
|
-
require "graphql/backtrace/tracer"
|
|
6
|
-
require "graphql/backtrace/trace"
|
|
7
4
|
module GraphQL
|
|
8
5
|
# Wrap unhandled errors with {TracedError}.
|
|
9
6
|
#
|
|
@@ -24,7 +21,7 @@ module GraphQL
|
|
|
24
21
|
def_delegators :to_a, :each, :[]
|
|
25
22
|
|
|
26
23
|
def self.use(schema_defn)
|
|
27
|
-
schema_defn.
|
|
24
|
+
schema_defn.using_backtrace = true
|
|
28
25
|
end
|
|
29
26
|
|
|
30
27
|
def initialize(context, value: nil)
|
|
@@ -40,20 +37,5 @@ module GraphQL
|
|
|
40
37
|
def to_a
|
|
41
38
|
@table.to_backtrace
|
|
42
39
|
end
|
|
43
|
-
|
|
44
|
-
# Used for internal bookkeeping
|
|
45
|
-
# @api private
|
|
46
|
-
class Frame
|
|
47
|
-
attr_reader :path, :query, :ast_node, :object, :field, :arguments, :parent_frame
|
|
48
|
-
def initialize(path:, query:, ast_node:, object:, field:, arguments:, parent_frame:)
|
|
49
|
-
@path = path
|
|
50
|
-
@query = query
|
|
51
|
-
@ast_node = ast_node
|
|
52
|
-
@field = field
|
|
53
|
-
@object = object
|
|
54
|
-
@arguments = arguments
|
|
55
|
-
@parent_frame = parent_frame
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
40
|
end
|
|
59
41
|
end
|
data/lib/graphql/current.rb
CHANGED
|
@@ -22,7 +22,7 @@ module GraphQL
|
|
|
22
22
|
# ]
|
|
23
23
|
#
|
|
24
24
|
module Current
|
|
25
|
-
# @return [String, nil] Comma-joined operation names for the currently-running {Multiplex}. `nil` if all operations are anonymous.
|
|
25
|
+
# @return [String, nil] Comma-joined operation names for the currently-running {Execution::Multiplex}. `nil` if all operations are anonymous.
|
|
26
26
|
def self.operation_name
|
|
27
27
|
if (m = Fiber[:__graphql_current_multiplex])
|
|
28
28
|
m.context[:__graphql_current_operation_name] ||= begin
|
|
@@ -48,5 +48,10 @@ module GraphQL
|
|
|
48
48
|
def self.dataloader_source_class
|
|
49
49
|
Fiber[:__graphql_current_dataloader_source]&.class
|
|
50
50
|
end
|
|
51
|
+
|
|
52
|
+
# @return [GraphQL::Dataloader::Source, nil] The currently-running source, if there is one
|
|
53
|
+
def self.dataloader_source
|
|
54
|
+
Fiber[:__graphql_current_dataloader_source]
|
|
55
|
+
end
|
|
51
56
|
end
|
|
52
57
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require "action_controller"
|
|
3
|
+
|
|
4
|
+
module Graphql
|
|
5
|
+
class Dashboard < Rails::Engine
|
|
6
|
+
class ApplicationController < ActionController::Base
|
|
7
|
+
protect_from_forgery with: :exception
|
|
8
|
+
prepend_view_path(File.expand_path("../views", __FILE__))
|
|
9
|
+
|
|
10
|
+
content_security_policy do |policy|
|
|
11
|
+
policy.default_src(:self) if policy.default_src(*policy.default_src).blank?
|
|
12
|
+
policy.connect_src(:self) if policy.connect_src(*policy.connect_src).blank?
|
|
13
|
+
policy.base_uri(:none) if policy.base_uri(*policy.base_uri).blank?
|
|
14
|
+
policy.font_src(:self) if policy.font_src(*policy.font_src).blank?
|
|
15
|
+
policy.img_src(:self, :data) if policy.img_src(*policy.img_src).blank?
|
|
16
|
+
policy.object_src(:none) if policy.object_src(*policy.object_src).blank?
|
|
17
|
+
policy.script_src(:self) if policy.script_src(*policy.script_src).blank?
|
|
18
|
+
policy.style_src(:self) if policy.style_src(*policy.style_src).blank?
|
|
19
|
+
policy.form_action(:self) if policy.form_action(*policy.form_action).blank?
|
|
20
|
+
policy.frame_ancestors(:none) if policy.frame_ancestors(*policy.frame_ancestors).blank?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def schema_class
|
|
24
|
+
@schema_class ||= begin
|
|
25
|
+
schema_param = request.query_parameters["schema"] || params[:schema]
|
|
26
|
+
case schema_param
|
|
27
|
+
when Class
|
|
28
|
+
schema_param
|
|
29
|
+
when String
|
|
30
|
+
schema_param.constantize
|
|
31
|
+
else
|
|
32
|
+
raise "Missing `params[:schema]`, please provide a class or string to `mount GraphQL::Dashboard, schema: ...`"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
helper_method :schema_class
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
ActiveSupport.run_load_hooks(:graphql_dashboard_application_controller, GraphQL::Dashboard::ApplicationController)
|
|
@@ -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
|