Method: GraphQL::Analysis::QueryComplexity#result

Defined in:
lib/graphql/analysis/query_complexity.rb

#resultObject

Override this method to use the complexity result



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/graphql/analysis/query_complexity.rb', line 15

def result
  case subject.schema.complexity_cost_calculation_mode_for(subject.context)
  when :future
    max_possible_complexity
  when :legacy
    max_possible_complexity(mode: :legacy)
  when :compare
    future_complexity = max_possible_complexity
    legacy_complexity = max_possible_complexity(mode: :legacy)
    if future_complexity != legacy_complexity
      subject.schema.legacy_complexity_cost_calculation_mismatch(subject, future_complexity, legacy_complexity)
    else
      future_complexity
    end
  when nil
    subject.logger.warn "      GraphQL-Ruby's complexity cost system is getting some \"breaking fixes\" in a future version. See the migration notes at https://graphql-ruby.org/api-doc/\#{GraphQL::VERSION}/GraphQL/Schema.html#complexity_cost_calculation_mode_for-class_method\n\n      To opt into the future behavior, configure your schema (\#{subject.schema.name ? subject.schema.name : subject.schema.ancestors}) with:\n\n        complexity_cost_calculation_mode(:future) # or `:legacy`, `:compare`\n\n    GRAPHQL\n    max_possible_complexity(mode: :legacy)\n  else\n    raise ArgumentError, \"Expected `:future`, `:legacy`, `:compare`, or `nil` from `\#{query.schema}.complexity_cost_calculation_mode_for` but got: \#{query.schema.complexity_cost_calculation_mode.inspect}\"\n  end\nend\n"