[GraphQL] use Execution::Interpreter
GraphQL-Ruby 1.9.0 includes a new runtime module which you may use for your schema. Eventually, it will become the default.
This commit is contained in:
parent
7478a51846
commit
0a928b2d6b
2 changed files with 23 additions and 12 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)
|
||||
|
|
|
@ -59,18 +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
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue