diff --git a/lib/graphql/analysis/query_complexity.rb b/lib/graphql/analysis/query_complexity.rb index 1cf1c48cf52..4a90824b4c4 100644 --- a/lib/graphql/analysis/query_complexity.rb +++ b/lib/graphql/analysis/query_complexity.rb @@ -35,7 +35,7 @@ def result complexity_cost_calculation_mode(:future) # or `:legacy`, `:compare` GRAPHQL - max_possible_complexity + max_possible_complexity(mode: :legacy) else 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}" end diff --git a/spec/graphql/analysis/query_complexity_spec.rb b/spec/graphql/analysis/query_complexity_spec.rb index 2afd152e504..818ea5b596b 100644 --- a/spec/graphql/analysis/query_complexity_spec.rb +++ b/spec/graphql/analysis/query_complexity_spec.rb @@ -958,6 +958,30 @@ def self.legacy_complexity_cost_calculation_mismatch(query, future_cpx, legacy_c assert_includes stdout, "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 +To opt into the future behavior, configure your schema (MaxOfPossibleScopes) with: + + complexity_cost_calculation_mode(:future) # or `:legacy`, `:compare`" + end + + it "uses legacy mode" do + cost = nil + assert_nil MaxOfPossibleScopes.complexity_cost_calculation_mode + stdout, _stderr = capture_io do + cost = MaxOfPossibleScopes.cost(%| + { + entity { + ...on Farm { name } + ...on Producer { name } + } + } + |) + end + puts stdout + + assert_equal 6, cost + + assert_includes stdout, "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 + To opt into the future behavior, configure your schema (MaxOfPossibleScopes) with: complexity_cost_calculation_mode(:future) # or `:legacy`, `:compare`"