...

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

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

     1  package validator
     2  
     3  import (
     4  	"github.com/vektah/gqlparser/v2/ast"
     5  
     6  	//nolint:revive // Validator rules each use dot imports for convenience.
     7  	. "github.com/vektah/gqlparser/v2/validator"
     8  )
     9  
    10  func init() {
    11  	AddRule("UniqueInputFieldNames", func(observers *Events, addError AddErrFunc) {
    12  		observers.OnValue(func(walker *Walker, value *ast.Value) {
    13  			if value.Kind != ast.ObjectValue {
    14  				return
    15  			}
    16  
    17  			seen := map[string]bool{}
    18  			for _, field := range value.Children {
    19  				if seen[field.Name] {
    20  					addError(
    21  						Message(`There can be only one input field named "%s".`, field.Name),
    22  						At(field.Position),
    23  					)
    24  				}
    25  				seen[field.Name] = true
    26  			}
    27  		})
    28  	})
    29  }
    30  

View as plain text