...
1 package validator
2
3 import (
4 "github.com/vektah/gqlparser/ast"
5 . "github.com/vektah/gqlparser/validator"
6 )
7
8 func init() {
9 AddRule("UniqueDirectivesPerLocation", func(observers *Events, addError AddErrFunc) {
10 observers.OnDirectiveList(func(walker *Walker, directives []*ast.Directive) {
11 seen := map[string]bool{}
12
13 for _, dir := range directives {
14 if seen[dir.Name] {
15 addError(
16 Message(`The directive "%s" can only be used once at this location.`, dir.Name),
17 At(dir.Position),
18 )
19 }
20 seen[dir.Name] = true
21 }
22 })
23 })
24 }
25
View as plain text