Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement UniqueOperationNames validator
- Loading branch information
Adam Scarr
committed
Jul 11, 2018
1 parent
ca444e3
commit 90a6704
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package validator | ||
|
||
import ( | ||
"github.com/vektah/gqlparser" | ||
) | ||
|
||
func init() { | ||
addRule("UniqueOperationNames", func(observers *Events, addError addErrFunc) { | ||
seen := map[string]bool{} | ||
|
||
observers.OnOperation(func(walker *Walker, operation *gqlparser.OperationDefinition) { | ||
if seen[operation.Name] { | ||
addError( | ||
Message(`There can be only one operation named "%s".`, operation.Name), | ||
) | ||
} | ||
seen[operation.Name] = true | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters