graphql 2.4.3 → 2.5.3
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/graphql/analysis/analyzer.rb +2 -1
- data/lib/graphql/analysis/query_complexity.rb +87 -7
- data/lib/graphql/analysis/visitor.rb +38 -41
- data/lib/graphql/analysis.rb +15 -12
- 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 +7 -2
- 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 +64 -0
- data/lib/graphql/dataloader/active_record_source.rb +26 -0
- data/lib/graphql/dataloader/async_dataloader.rb +21 -9
- data/lib/graphql/dataloader/null_dataloader.rb +1 -1
- data/lib/graphql/dataloader/source.rb +3 -3
- data/lib/graphql/dataloader.rb +43 -14
- data/lib/graphql/dig.rb +2 -1
- data/lib/graphql/execution/interpreter/resolve.rb +3 -3
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +34 -4
- data/lib/graphql/execution/interpreter/runtime.rb +96 -52
- data/lib/graphql/execution/interpreter.rb +16 -7
- data/lib/graphql/execution/multiplex.rb +6 -5
- data/lib/graphql/introspection/directive_location_enum.rb +1 -1
- data/lib/graphql/invalid_name_error.rb +1 -1
- data/lib/graphql/invalid_null_error.rb +19 -16
- data/lib/graphql/language/cache.rb +13 -0
- data/lib/graphql/language/document_from_schema_definition.rb +8 -7
- data/lib/graphql/language/lexer.rb +11 -4
- data/lib/graphql/language/nodes.rb +3 -0
- data/lib/graphql/language/parser.rb +15 -8
- data/lib/graphql/language/printer.rb +8 -8
- data/lib/graphql/language/static_visitor.rb +37 -33
- data/lib/graphql/language/visitor.rb +59 -55
- data/lib/graphql/pagination/connection.rb +1 -1
- data/lib/graphql/query/context/scoped_context.rb +1 -1
- data/lib/graphql/query/context.rb +7 -5
- data/lib/graphql/query/variable_validation_error.rb +1 -1
- data/lib/graphql/query.rb +22 -32
- data/lib/graphql/railtie.rb +7 -0
- data/lib/graphql/schema/addition.rb +1 -1
- data/lib/graphql/schema/always_visible.rb +1 -0
- data/lib/graphql/schema/argument.rb +7 -8
- data/lib/graphql/schema/build_from_definition.rb +99 -53
- data/lib/graphql/schema/directive/flagged.rb +3 -1
- data/lib/graphql/schema/directive.rb +2 -2
- data/lib/graphql/schema/enum.rb +36 -1
- data/lib/graphql/schema/enum_value.rb +1 -1
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +27 -13
- data/lib/graphql/schema/field_extension.rb +1 -1
- data/lib/graphql/schema/has_single_input_argument.rb +3 -1
- data/lib/graphql/schema/input_object.rb +77 -40
- data/lib/graphql/schema/interface.rb +3 -2
- data/lib/graphql/schema/list.rb +1 -1
- data/lib/graphql/schema/loader.rb +1 -1
- data/lib/graphql/schema/member/has_arguments.rb +25 -17
- 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 +19 -1
- data/lib/graphql/schema/member/has_interfaces.rb +5 -5
- data/lib/graphql/schema/member/has_validators.rb +1 -1
- data/lib/graphql/schema/member/scoped.rb +1 -1
- data/lib/graphql/schema/member/type_system_helpers.rb +1 -1
- data/lib/graphql/schema/member.rb +1 -0
- data/lib/graphql/schema/object.rb +25 -8
- data/lib/graphql/schema/relay_classic_mutation.rb +0 -1
- data/lib/graphql/schema/resolver.rb +12 -10
- data/lib/graphql/schema/subscription.rb +52 -6
- data/lib/graphql/schema/union.rb +1 -1
- data/lib/graphql/schema/validator/required_validator.rb +23 -6
- data/lib/graphql/schema/validator.rb +1 -1
- data/lib/graphql/schema/visibility/migration.rb +1 -0
- data/lib/graphql/schema/visibility/profile.rb +98 -244
- data/lib/graphql/schema/visibility/visit.rb +190 -0
- data/lib/graphql/schema/visibility.rb +178 -38
- data/lib/graphql/schema/warden.rb +18 -5
- data/lib/graphql/schema.rb +266 -54
- data/lib/graphql/static_validation/all_rules.rb +1 -1
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +1 -1
- 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/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/required_arguments_are_present.rb +1 -1
- 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 +1 -1
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
- data/lib/graphql/static_validation/validation_context.rb +1 -0
- data/lib/graphql/static_validation/validator.rb +6 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +1 -1
- 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 +7 -4
- 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/memory_backend.rb +60 -0
- data/lib/graphql/tracing/detailed_trace/redis_backend.rb +72 -0
- data/lib/graphql/tracing/detailed_trace.rb +93 -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 +182 -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 +734 -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 +62 -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/types/relay/connection_behaviors.rb +3 -3
- data/lib/graphql/types/relay/edge_behaviors.rb +2 -2
- data/lib/graphql/types.rb +18 -11
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +55 -47
- metadata +146 -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/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
|
@@ -41,12 +41,17 @@ module GraphQL
|
|
41
41
|
# @see GraphQL::Field#path for a string identifying this field
|
42
42
|
# @return [GraphQL::Field, nil] The currently-running field, if there is one.
|
43
43
|
def self.field
|
44
|
-
|
44
|
+
Fiber[:__graphql_runtime_info]&.values&.first&.current_field
|
45
45
|
end
|
46
46
|
|
47
47
|
# @return [Class, nil] The currently-running {Dataloader::Source} class, if there is one.
|
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,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
|