UNPKG

988 BJavaScriptView Raw
1import { GraphQLError } from "../../error/GraphQLError.mjs";
2import { Kind } from "../../language/kinds.mjs";
3import { isExecutableDefinitionNode } from "../../language/predicates.mjs";
4
5/**
6 * Executable definitions
7 *
8 * A GraphQL document is only valid for execution if all definitions are either
9 * operation or fragment definitions.
10 */
11export function ExecutableDefinitionsRule(context) {
12 return {
13 Document: function Document(node) {
14 for (var _i2 = 0, _node$definitions2 = node.definitions; _i2 < _node$definitions2.length; _i2++) {
15 var definition = _node$definitions2[_i2];
16
17 if (!isExecutableDefinitionNode(definition)) {
18 var defName = definition.kind === Kind.SCHEMA_DEFINITION || definition.kind === Kind.SCHEMA_EXTENSION ? 'schema' : '"' + definition.name.value + '"';
19 context.reportError(new GraphQLError("The ".concat(defName, " definition is not executable."), definition));
20 }
21 }
22
23 return false;
24 }
25 };
26}