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