UNPKG

apollo-mobx

Version:

HOC for querying graphql server

37 lines (36 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var apollo_link_1 = require("apollo-link"); var graphql_1 = require("graphql"); var printer_1 = require("graphql/language/printer"); var MockLink = (function (_super) { tslib_1.__extends(MockLink, _super); function MockLink(params) { var _this = _super.call(this) || this; _this.schema = params.schema; _this.rootValue = params.rootValue; _this.context = params.context; return _this; } MockLink.prototype.request = function (operation) { var _this = this; var request = tslib_1.__assign({}, operation, { query: printer_1.print(operation.query) }); return new apollo_link_1.Observable(function (observer) { graphql_1.graphql(_this.schema, request.query, _this.rootValue, _this.context, request.variables, request.operationName) .then(function (data) { if (!observer.closed) { observer.next(data); observer.complete(); } }) .catch(function (error) { if (!observer.closed) { observer.error(error); } }); }); }; return MockLink; }(apollo_link_1.ApolloLink)); exports.default = MockLink;