UNPKG

graphql

Version:

A Query Language and Runtime which can target any service.

21 lines 897 B
import { GraphQLError } from "../../error/GraphQLError.mjs"; export function UniqueOperationNamesRule(context) { const knownOperationNames = new Map(); return { OperationDefinition(node) { const operationName = node.name; if (operationName != null) { const knownOperationName = knownOperationNames.get(operationName.value); if (knownOperationName != null) { context.reportError(new GraphQLError(`There can be only one operation named "${operationName.value}".`, { nodes: [knownOperationName, operationName] })); } else { knownOperationNames.set(operationName.value, operationName); } } return false; }, FragmentDefinition: () => false, }; } //# sourceMappingURL=UniqueOperationNamesRule.js.map