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