ExecutableDefinitionsRule.mjs 988 B

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