UNPKG

882 BJavaScriptView Raw
1import { GraphQLError } from "../../error/GraphQLError.mjs";
2
3/**
4 * Unique operation names
5 *
6 * A GraphQL document is only valid if all defined operations have unique names.
7 */
8export function UniqueOperationNamesRule(context) {
9 var knownOperationNames = Object.create(null);
10 return {
11 OperationDefinition: function OperationDefinition(node) {
12 var operationName = node.name;
13
14 if (operationName) {
15 if (knownOperationNames[operationName.value]) {
16 context.reportError(new GraphQLError("There can be only one operation named \"".concat(operationName.value, "\"."), [knownOperationNames[operationName.value], operationName]));
17 } else {
18 knownOperationNames[operationName.value] = operationName;
19 }
20 }
21
22 return false;
23 },
24 FragmentDefinition: function FragmentDefinition() {
25 return false;
26 }
27 };
28}