ExecutableDefinitions.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.nonExecutableDefinitionMessage = nonExecutableDefinitionMessage;
  6. exports.ExecutableDefinitions = ExecutableDefinitions;
  7. var _GraphQLError = require("../../error/GraphQLError");
  8. var _kinds = require("../../language/kinds");
  9. var _predicates = require("../../language/predicates");
  10. function nonExecutableDefinitionMessage(defName) {
  11. return "The ".concat(defName, " definition is not executable.");
  12. }
  13. /**
  14. * Executable definitions
  15. *
  16. * A GraphQL document is only valid for execution if all definitions are either
  17. * operation or fragment definitions.
  18. */
  19. function ExecutableDefinitions(context) {
  20. return {
  21. Document: function Document(node) {
  22. for (var _i2 = 0, _node$definitions2 = node.definitions; _i2 < _node$definitions2.length; _i2++) {
  23. var definition = _node$definitions2[_i2];
  24. if (!(0, _predicates.isExecutableDefinitionNode)(definition)) {
  25. context.reportError(new _GraphQLError.GraphQLError(nonExecutableDefinitionMessage(definition.kind === _kinds.Kind.SCHEMA_DEFINITION || definition.kind === _kinds.Kind.SCHEMA_EXTENSION ? 'schema' : definition.name.value), definition));
  26. }
  27. }
  28. return false;
  29. }
  30. };
  31. }