UNPKG

1.5 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var apollo_link_1 = require("apollo-link");
5var execute_1 = require("graphql/execution/execute");
6var SchemaLink = (function (_super) {
7 tslib_1.__extends(SchemaLink, _super);
8 function SchemaLink(_a) {
9 var schema = _a.schema, rootValue = _a.rootValue, context = _a.context;
10 var _this = _super.call(this) || this;
11 _this.schema = schema;
12 _this.rootValue = rootValue;
13 _this.context = context;
14 return _this;
15 }
16 SchemaLink.prototype.request = function (operation) {
17 var _this = this;
18 return new apollo_link_1.Observable(function (observer) {
19 Promise.resolve(execute_1.execute(_this.schema, operation.query, _this.rootValue, typeof _this.context === 'function'
20 ? _this.context(operation)
21 : _this.context, operation.variables, operation.operationName))
22 .then(function (data) {
23 if (!observer.closed) {
24 observer.next(data);
25 observer.complete();
26 }
27 })
28 .catch(function (error) {
29 if (!observer.closed) {
30 observer.error(error);
31 }
32 });
33 });
34 };
35 return SchemaLink;
36}(apollo_link_1.ApolloLink));
37exports.SchemaLink = SchemaLink;
38exports.default = SchemaLink;
39//# sourceMappingURL=index.js.map
\No newline at end of file