[GraphQL] use Execution::Interpreter (+ update Skylight) (#4626)
GraphQL : mise à jour de l'analyse des performances
This commit is contained in:
commit
897cdf6632
5 changed files with 38 additions and 16 deletions
|
@ -242,7 +242,7 @@ GEM
|
||||||
graphiql-rails (1.7.0)
|
graphiql-rails (1.7.0)
|
||||||
railties
|
railties
|
||||||
sprockets-rails
|
sprockets-rails
|
||||||
graphql (1.9.15)
|
graphql (1.9.16)
|
||||||
graphql-batch (0.4.1)
|
graphql-batch (0.4.1)
|
||||||
graphql (>= 1.3, < 2)
|
graphql (>= 1.3, < 2)
|
||||||
promise.rb (~> 0.7.2)
|
promise.rb (~> 0.7.2)
|
||||||
|
@ -614,9 +614,9 @@ GEM
|
||||||
rack (~> 2.0)
|
rack (~> 2.0)
|
||||||
rack-protection (= 2.0.5)
|
rack-protection (= 2.0.5)
|
||||||
tilt (~> 2.0)
|
tilt (~> 2.0)
|
||||||
skylight (3.1.2)
|
skylight (4.2.1)
|
||||||
skylight-core (= 3.1.2)
|
skylight-core (= 4.2.1)
|
||||||
skylight-core (3.1.2)
|
skylight-core (4.2.1)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
smart_listing (1.2.2)
|
smart_listing (1.2.2)
|
||||||
coffee-rails
|
coffee-rails
|
||||||
|
|
|
@ -59,19 +59,29 @@ class Api::V2::Schema < GraphQL::Schema
|
||||||
raise GraphQL::ExecutionError.new("An object of type #{error.type.graphql_name} was hidden due to permissions", extensions: { code: :unauthorized })
|
raise GraphQL::ExecutionError.new("An object of type #{error.type.graphql_name} was hidden due to permissions", extensions: { code: :unauthorized })
|
||||||
end
|
end
|
||||||
|
|
||||||
middleware(GraphQL::Schema::TimeoutMiddleware.new(max_seconds: 5) do |_, query|
|
use GraphQL::Execution::Interpreter
|
||||||
Rails.logger.info("GraphQL Timeout: #{query.query_string}")
|
use GraphQL::Analysis::AST
|
||||||
end)
|
use GraphQL::Schema::Timeout, max_seconds: 5
|
||||||
|
use GraphQL::Batch
|
||||||
|
use GraphQL::Backtrace
|
||||||
|
|
||||||
if Rails.env.development?
|
if Rails.env.development?
|
||||||
query_analyzer(GraphQL::Analysis::QueryComplexity.new do |_, complexity|
|
class LogQueryDepth < GraphQL::Analysis::AST::QueryDepth
|
||||||
Rails.logger.info("[GraphQL Query Complexity] #{complexity}")
|
def result
|
||||||
end)
|
Rails.logger.info("[GraphQL Query Depth] #{super}")
|
||||||
query_analyzer(GraphQL::Analysis::QueryDepth.new do |_, depth|
|
end
|
||||||
Rails.logger.info("[GraphQL Query Depth] #{depth}")
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
use GraphQL::Batch
|
class LogQueryComplexity < GraphQL::Analysis::AST::QueryComplexity
|
||||||
use GraphQL::Tracing::SkylightTracing
|
def result
|
||||||
|
Rails.logger.info("[GraphQL Query Complexity] #{super}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
query_analyzer(LogQueryComplexity)
|
||||||
|
query_analyzer(LogQueryDepth)
|
||||||
|
else
|
||||||
|
query_analyzer(GraphQL::Analysis::AST::MaxQueryComplexity)
|
||||||
|
query_analyzer(GraphQL::Analysis::AST::MaxQueryDepth)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,5 +49,7 @@ module TPS
|
||||||
debounce_delay: 3000,
|
debounce_delay: 3000,
|
||||||
status_visible_duration: 6000
|
status_visible_duration: 6000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.skylight.probes += [:graphql]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,6 +21,7 @@ describe ApplicationController, type: :controller do
|
||||||
let(:payload) { {} }
|
let(:payload) { {} }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
allow(@controller).to receive(:content_type).and_return('')
|
||||||
allow(@controller).to receive(:current_user).and_return(current_user)
|
allow(@controller).to receive(:current_user).and_return(current_user)
|
||||||
expect(@controller).to receive(:current_instructeur).and_return(current_instructeur)
|
expect(@controller).to receive(:current_instructeur).and_return(current_instructeur)
|
||||||
expect(@controller).to receive(:current_administrateur).and_return(current_administrateur)
|
expect(@controller).to receive(:current_administrateur).and_return(current_administrateur)
|
||||||
|
@ -42,6 +43,8 @@ describe ApplicationController, type: :controller do
|
||||||
payload.delete(key)
|
payload.delete(key)
|
||||||
end
|
end
|
||||||
expect(payload).to eq({
|
expect(payload).to eq({
|
||||||
|
sk_rendered_format: nil,
|
||||||
|
sk_variant: [],
|
||||||
user_agent: 'Rails Testing',
|
user_agent: 'Rails Testing',
|
||||||
user_roles: 'Guest'
|
user_roles: 'Guest'
|
||||||
})
|
})
|
||||||
|
@ -61,6 +64,8 @@ describe ApplicationController, type: :controller do
|
||||||
payload.delete(key)
|
payload.delete(key)
|
||||||
end
|
end
|
||||||
expect(payload).to eq({
|
expect(payload).to eq({
|
||||||
|
sk_rendered_format: nil,
|
||||||
|
sk_variant: [],
|
||||||
user_agent: 'Rails Testing',
|
user_agent: 'Rails Testing',
|
||||||
user_id: current_user.id,
|
user_id: current_user.id,
|
||||||
user_email: current_user.email,
|
user_email: current_user.email,
|
||||||
|
@ -85,6 +90,8 @@ describe ApplicationController, type: :controller do
|
||||||
payload.delete(key)
|
payload.delete(key)
|
||||||
end
|
end
|
||||||
expect(payload).to eq({
|
expect(payload).to eq({
|
||||||
|
sk_rendered_format: nil,
|
||||||
|
sk_variant: [],
|
||||||
user_agent: 'Rails Testing',
|
user_agent: 'Rails Testing',
|
||||||
user_id: current_user.id,
|
user_id: current_user.id,
|
||||||
user_email: current_user.email,
|
user_email: current_user.email,
|
||||||
|
|
|
@ -4,6 +4,7 @@ describe Manager::ApplicationController, type: :controller do
|
||||||
let(:payload) { {} }
|
let(:payload) { {} }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
allow(@controller).to receive(:content_type).and_return('')
|
||||||
allow(@controller).to receive(:current_user).and_return(current_user)
|
allow(@controller).to receive(:current_user).and_return(current_user)
|
||||||
@controller.send(:append_info_to_payload, payload)
|
@controller.send(:append_info_to_payload, payload)
|
||||||
end
|
end
|
||||||
|
@ -13,6 +14,8 @@ describe Manager::ApplicationController, type: :controller do
|
||||||
payload.delete(key)
|
payload.delete(key)
|
||||||
end
|
end
|
||||||
expect(payload).to eq({
|
expect(payload).to eq({
|
||||||
|
sk_rendered_format: nil,
|
||||||
|
sk_variant: [],
|
||||||
user_agent: 'Rails Testing',
|
user_agent: 'Rails Testing',
|
||||||
user_id: current_user.id,
|
user_id: current_user.id,
|
||||||
user_email: current_user.email
|
user_email: current_user.email
|
||||||
|
|
Loading…
Reference in a new issue