ExecutableDefinitionsRule.js 1.1 KB

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