Class: GraphQL::Analysis::AST::MaxQueryComplexity

Inherits:
QueryComplexity show all
Defined in:
lib/graphql/analysis/ast/max_query_complexity.rb

Overview

Used under the hood to implement complexity validation, see Schema#max_complexity and Query#max_complexity

Instance Method Summary collapse

Methods inherited from QueryComplexity

#initialize, #max_possible_complexity, #on_enter_field, #on_leave_field

Methods inherited from Analyzer

#analyze?, #initialize

Constructor Details

This class inherits a constructor from GraphQL::Analysis::AST::QueryComplexity

Instance Method Details

#resultObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/graphql/analysis/ast/max_query_complexity.rb', line 9

def result
  return if query.max_complexity.nil?

  total_complexity = max_possible_complexity

  if total_complexity > query.max_complexity
    GraphQL::AnalysisError.new("Query has complexity of #{total_complexity}, which exceeds max complexity of #{query.max_complexity}")
  else
    nil
  end
end