522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
|
# File 'lib/graphql/schema/field.rb', line 522
def complexity(new_complexity = nil)
case new_complexity
when Proc
if new_complexity.parameters.size != 3
fail(
"A complexity proc should always accept 3 parameters: ctx, args, child_complexity. "\
"E.g.: complexity ->(ctx, args, child_complexity) { child_complexity * args[:limit] }"
)
else
@complexity = new_complexity
end
when Numeric
@complexity = new_complexity
when nil
if @resolver_class
@complexity || @resolver_class.complexity || 1
else
@complexity || 1
end
else
raise("Invalid complexity: #{new_complexity.inspect} on #{@name}")
end
end
|