[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)
|
||||
railties
|
||||
sprockets-rails
|
||||
graphql (1.9.15)
|
||||
graphql (1.9.16)
|
||||
graphql-batch (0.4.1)
|
||||
graphql (>= 1.3, < 2)
|
||||
promise.rb (~> 0.7.2)
|
||||
|
@ -614,9 +614,9 @@ GEM
|
|||
rack (~> 2.0)
|
||||
rack-protection (= 2.0.5)
|
||||
tilt (~> 2.0)
|
||||
skylight (3.1.2)
|
||||
skylight-core (= 3.1.2)
|
||||
skylight-core (3.1.2)
|
||||
skylight (4.2.1)
|
||||
skylight-core (= 4.2.1)
|
||||
skylight-core (4.2.1)
|
||||
activesupport (>= 4.2.0)
|
||||
smart_listing (1.2.2)
|
||||
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 })
|
||||
end
|
||||
|
||||
middleware(GraphQL::Schema::TimeoutMiddleware.new(max_seconds: 5) do |_, query|
|
||||
Rails.logger.info("GraphQL Timeout: #{query.query_string}")
|
||||
end)
|
||||
use GraphQL::Execution::Interpreter
|
||||
use GraphQL::Analysis::AST
|
||||
use GraphQL::Schema::Timeout, max_seconds: 5
|
||||
use GraphQL::Batch
|
||||
use GraphQL::Backtrace
|
||||
|
||||
if Rails.env.development?
|
||||
query_analyzer(GraphQL::Analysis::QueryComplexity.new do |_, complexity|
|
||||
Rails.logger.info("[GraphQL Query Complexity] #{complexity}")
|
||||
end)
|
||||
query_analyzer(GraphQL::Analysis::QueryDepth.new do |_, depth|
|
||||
Rails.logger.info("[GraphQL Query Depth] #{depth}")
|
||||
end)
|
||||
end
|
||||
class LogQueryDepth < GraphQL::Analysis::AST::QueryDepth
|
||||
def result
|
||||
Rails.logger.info("[GraphQL Query Depth] #{super}")
|
||||
end
|
||||
end
|
||||
|
||||
use GraphQL::Batch
|
||||
use GraphQL::Tracing::SkylightTracing
|
||||
class LogQueryComplexity < GraphQL::Analysis::AST::QueryComplexity
|
||||
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
|
||||
|
|
|
@ -49,5 +49,7 @@ module TPS
|
|||
debounce_delay: 3000,
|
||||
status_visible_duration: 6000
|
||||
}
|
||||
|
||||
config.skylight.probes += [:graphql]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,7 @@ describe ApplicationController, type: :controller do
|
|||
let(:payload) { {} }
|
||||
|
||||
before do
|
||||
allow(@controller).to receive(:content_type).and_return('')
|
||||
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_administrateur).and_return(current_administrateur)
|
||||
|
@ -42,6 +43,8 @@ describe ApplicationController, type: :controller do
|
|||
payload.delete(key)
|
||||
end
|
||||
expect(payload).to eq({
|
||||
sk_rendered_format: nil,
|
||||
sk_variant: [],
|
||||
user_agent: 'Rails Testing',
|
||||
user_roles: 'Guest'
|
||||
})
|
||||
|
@ -61,6 +64,8 @@ describe ApplicationController, type: :controller do
|
|||
payload.delete(key)
|
||||
end
|
||||
expect(payload).to eq({
|
||||
sk_rendered_format: nil,
|
||||
sk_variant: [],
|
||||
user_agent: 'Rails Testing',
|
||||
user_id: current_user.id,
|
||||
user_email: current_user.email,
|
||||
|
@ -85,6 +90,8 @@ describe ApplicationController, type: :controller do
|
|||
payload.delete(key)
|
||||
end
|
||||
expect(payload).to eq({
|
||||
sk_rendered_format: nil,
|
||||
sk_variant: [],
|
||||
user_agent: 'Rails Testing',
|
||||
user_id: current_user.id,
|
||||
user_email: current_user.email,
|
||||
|
|
|
@ -4,6 +4,7 @@ describe Manager::ApplicationController, type: :controller do
|
|||
let(:payload) { {} }
|
||||
|
||||
before do
|
||||
allow(@controller).to receive(:content_type).and_return('')
|
||||
allow(@controller).to receive(:current_user).and_return(current_user)
|
||||
@controller.send(:append_info_to_payload, payload)
|
||||
end
|
||||
|
@ -13,6 +14,8 @@ describe Manager::ApplicationController, type: :controller do
|
|||
payload.delete(key)
|
||||
end
|
||||
expect(payload).to eq({
|
||||
sk_rendered_format: nil,
|
||||
sk_variant: [],
|
||||
user_agent: 'Rails Testing',
|
||||
user_id: current_user.id,
|
||||
user_email: current_user.email
|
||||
|
|
Loading…
Reference in a new issue