...

Source file src/github.com/vektah/gqlparser/validator/rules/unique_variable_names.go

Documentation: github.com/vektah/gqlparser/validator/rules

     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("UniqueVariableNames", func(observers *Events, addError AddErrFunc) {
    10  		observers.OnOperation(func(walker *Walker, operation *ast.OperationDefinition) {
    11  			seen := map[string]bool{}
    12  			for _, def := range operation.VariableDefinitions {
    13  				if seen[def.Variable] {
    14  					addError(
    15  						Message(`There can be only one variable named "%s".`, def.Variable),
    16  						At(def.Position),
    17  					)
    18  				}
    19  				seen[def.Variable] = true
    20  			}
    21  		})
    22  	})
    23  }
    24  

View as plain text