Skip to content

Commit 28677d1

Browse files
author
Robert Mosolgo
authored
Merge pull request #3125 from nvh0412/chore/remove-redundant-loop-in-validator
Avoid redundant loop through rules_to_use in Validator#validate
2 parents 8ffd788 + 41ab9b4 commit 28677d1

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

lib/graphql/static_validation/validator.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ def validate(query, validate: true)
3232

3333
context = GraphQL::StaticValidation::ValidationContext.new(query, visitor_class)
3434

35-
# Attach legacy-style rules
36-
rules_to_use.each do |rule_class_or_module|
37-
if rule_class_or_module.method_defined?(:validate)
38-
rule_class_or_module.new.validate(context)
35+
# Attach legacy-style rules.
36+
# Only loop through rules if it has legacy-style rules
37+
unless (legacy_rules = rules_to_use - GraphQL::StaticValidation::ALL_RULES).empty?
38+
legacy_rules.each do |rule_class_or_module|
39+
if rule_class_or_module.method_defined?(:validate)
40+
rule_class_or_module.new.validate(context)
41+
end
3942
end
4043
end
4144

0 commit comments

Comments
 (0)