1 | import { GraphQLError } from "../../error/GraphQLError.mjs";
|
2 | import { Kind } from "../../language/kinds.mjs";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export function LoneAnonymousOperationRule(context) {
|
11 | var operationCount = 0;
|
12 | return {
|
13 | Document: function Document(node) {
|
14 | operationCount = node.definitions.filter(function (definition) {
|
15 | return definition.kind === Kind.OPERATION_DEFINITION;
|
16 | }).length;
|
17 | },
|
18 | OperationDefinition: function OperationDefinition(node) {
|
19 | if (!node.name && operationCount > 1) {
|
20 | context.reportError(new GraphQLError('This anonymous operation must be the only defined operation.', node));
|
21 | }
|
22 | }
|
23 | };
|
24 | }
|