code: func KnownDirectivesRule(context *ValidationContext) *ValidationRuleInstance {
  	visitorOpts := &visitor.VisitorOptions{
  		KindFuncMap: map[string]visitor.NamedVisitFuncs{
  			kinds.Directive: {
  				Kind: func(p visitor.VisitFuncParams) (string, interface{}) {
  					var action = visitor.ActionNoChange
  					var result interface{}
  					if node, ok := p.Node.(*ast.Directive); ok {
  
  						nodeName := ""
  						if node.Name != nil {
  							nodeName = node.Name.Value
  						}
  
  						var directiveDef *Directive
  						for _, def := range context.Schema().Directives() {
  							if def.Name == nodeName {
  								directiveDef = def
  							}
  						}
  						if directiveDef == nil {
  							return reportError(
  								context,
  								fmt.Sprintf(`Unknown directive "%v".`, nodeName),
  								[]ast.Node{node},
  							)
  						}
  
  						candidateLocation := getDirectiveLocationForASTPath(p.Ancestors)
  
  						directiveHasLocation := false
  						for _, loc := range directiveDef.Locations {
  							if loc == candidateLocation {
  								directiveHasLocation = true
  								break
  							}
  						}
  
  						if candidateLocation == "" {
  							reportError(
  								context,
  								MisplaceDirectiveMessage(nodeName, node.GetKind()),
  								[]ast.Node{node},
  							)
  						} else if !directiveHasLocation {
  							reportError(
  								context,
  								MisplaceDirectiveMessage(nodeName, candidateLocation),
  								[]ast.Node{node},
  							)
  						}
  
  					}
  					return action, result
  				},
  			},
  		},
  	}
  	return &ValidationRuleInstance{
  		VisitorOpts: visitorOpts,
  	}
  }
docs: // KnownDirectivesRule Known directives
  //
  // A GraphQL document is only valid if all `@directives` are known by the
  // schema and legally positioned.