UNPKG

1.38 kBJavaScriptView Raw
1import { __extends } from 'tslib';
2import { Observable, ApolloLink } from 'apollo-link';
3import { execute } from 'graphql/execution/execute';
4
5var SchemaLink = (function (_super) {
6 __extends(SchemaLink, _super);
7 function SchemaLink(_a) {
8 var schema = _a.schema, rootValue = _a.rootValue, context = _a.context;
9 var _this = _super.call(this) || this;
10 _this.schema = schema;
11 _this.rootValue = rootValue;
12 _this.context = context;
13 return _this;
14 }
15 SchemaLink.prototype.request = function (operation) {
16 var _this = this;
17 return new Observable(function (observer) {
18 Promise.resolve(execute(_this.schema, operation.query, _this.rootValue, typeof _this.context === 'function'
19 ? _this.context(operation)
20 : _this.context, operation.variables, operation.operationName))
21 .then(function (data) {
22 if (!observer.closed) {
23 observer.next(data);
24 observer.complete();
25 }
26 })
27 .catch(function (error) {
28 if (!observer.closed) {
29 observer.error(error);
30 }
31 });
32 });
33 };
34 return SchemaLink;
35}(ApolloLink));
36
37export default SchemaLink;
38export { SchemaLink };
39//# sourceMappingURL=bundle.esm.js.map