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