Skip to content

Commit

Permalink
Merge pull request #18 from dgraph-io/naman/sort
Browse files Browse the repository at this point in the history
fix(validate): fix race condition in rules sort
  • Loading branch information
NamanJain8 authored Dec 2, 2021
2 parents 4b0b96a + adfb85a commit f1c512b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ func AddRule(name string, f ruleFunc) {
// f is called once each time `Validate` is executed.
func AddRuleWithOrder(name string, order int, f ruleFunc) {
rules = append(rules, rule{name: name, order: order, rule: f})
sort.Slice(rules, func(i, j int) bool {
return rules[i].order < rules[j].order
})
}

func Validate(schema *Schema, doc *QueryDocument, variables map[string]interface{}) gqlerror.List {
var errs gqlerror.List

observers := &Events{}
sort.Slice(rules, func(i, j int) bool {
return rules[i].order < rules[j].order
})
for i := range rules {
rule := rules[i]
rule.rule(observers, func(options ...ErrorOption) {
Expand Down

0 comments on commit f1c512b

Please sign in to comment.