...
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("KnownDirectives", func(observers *Events, addError AddErrFunc) {
10 observers.OnDirective(func(walker *Walker, directive *ast.Directive) {
11 if directive.Definition == nil {
12 addError(
13 Message(`Unknown directive "%s".`, directive.Name),
14 At(directive.Position),
15 )
16 return
17 }
18
19 for _, loc := range directive.Definition.Locations {
20 if loc == directive.Location {
21 return
22 }
23 }
24
25 addError(
26 Message(`Directive "%s" may not be used on %s.`, directive.Name, directive.Location),
27 At(directive.Position),
28 )
29 })
30 })
31 }
32
View as plain text