graphql
Version:
A Query Language and Runtime which can target any service.
16 lines • 677 B
JavaScript
import { GraphQLError } from "../../error/GraphQLError.mjs";
import { Kind } from "../../language/kinds.mjs";
export function LoneAnonymousOperationRule(context) {
let operationCount = 0;
return {
Document(node) {
operationCount = node.definitions.filter((definition) => definition.kind === Kind.OPERATION_DEFINITION).length;
},
OperationDefinition(node) {
if (!node.name && operationCount > 1) {
context.reportError(new GraphQLError('This anonymous operation must be the only defined operation.', { nodes: node }));
}
},
};
}
//# sourceMappingURL=LoneAnonymousOperationRule.js.map