UNPKG

apollo-link-core

Version:

Flexible, lightweight transport layer for GraphQL

75 lines 2.46 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var link_1 = require("./link"); function validateLink(link) { if (link instanceof link_1.ApolloLink && typeof link.request === 'function') { return link; } else { throw new LinkError('Link does not extend ApolloLink and implement request', link); } } exports.validateLink = validateLink; function validateOperation(operation) { var OPERATION_FIELDS = ['query', 'operationName', 'variables', 'context']; for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) { var key = _a[_i]; if (OPERATION_FIELDS.indexOf(key) < 0) { throw new Error("illegal argument: " + key); } } return operation; } exports.validateOperation = validateOperation; var LinkError = (function (_super) { __extends(LinkError, _super); function LinkError(message, link) { var _this = _super.call(this, message) || this; _this.link = link; return _this; } return LinkError; }(Error)); exports.LinkError = LinkError; function toLink(link) { if (typeof link === 'function') { return new link_1.FunctionLink(link); } else { return link; } } exports.toLink = toLink; function isTerminating(link) { return link.request.length <= 1; } exports.isTerminating = isTerminating; function makePromise(observable) { var completed = false; return new Promise(function (resolve, reject) { observable.subscribe({ next: function (data) { if (completed) { console.warn("Promise Wrapper does not support multiple results from Observable"); } else { completed = true; resolve(data); } }, error: reject, }); }); } exports.makePromise = makePromise; //# sourceMappingURL=linkUtils.js.map