getOperationAST.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getOperationAST = getOperationAST;
  6. var _kinds = require("../language/kinds.js");
  7. /**
  8. * Returns an operation AST given a document AST and optionally an operation
  9. * name. If a name is not provided, an operation is only returned if only one is
  10. * provided in the document.
  11. */
  12. function getOperationAST(documentAST, operationName) {
  13. var operation = null;
  14. for (var _i2 = 0, _documentAST$definiti2 = documentAST.definitions; _i2 < _documentAST$definiti2.length; _i2++) {
  15. var definition = _documentAST$definiti2[_i2];
  16. if (definition.kind === _kinds.Kind.OPERATION_DEFINITION) {
  17. var _definition$name;
  18. if (operationName == null) {
  19. // If no operation name was provided, only return an Operation if there
  20. // is one defined in the document. Upon encountering the second, return
  21. // null.
  22. if (operation) {
  23. return null;
  24. }
  25. operation = definition;
  26. } else if (((_definition$name = definition.name) === null || _definition$name === void 0 ? void 0 : _definition$name.value) === operationName) {
  27. return definition;
  28. }
  29. }
  30. }
  31. return operation;
  32. }