...

Source file src/github.com/vektah/gqlparser/validator/rules/unique_operation_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("UniqueOperationNames", func(observers *Events, addError AddErrFunc) {
    10  		seen := map[string]bool{}
    11  
    12  		observers.OnOperation(func(walker *Walker, operation *ast.OperationDefinition) {
    13  			if seen[operation.Name] {
    14  				addError(
    15  					Message(`There can be only one operation named "%s".`, operation.Name),
    16  					At(operation.Position),
    17  				)
    18  			}
    19  			seen[operation.Name] = true
    20  		})
    21  	})
    22  }
    23  

View as plain text