1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var tslib = require('tslib');
|
6 | var graphql = require('graphql');
|
7 | var core = require('../core');
|
8 | var utilities = require('../../utilities');
|
9 | var errors = require('../../errors');
|
10 |
|
11 | function isLikeCloseEvent(val) {
|
12 | return utilities.isNonNullObject(val) && 'code' in val && 'reason' in val;
|
13 | }
|
14 | var GraphQLWsLink = (function (_super) {
|
15 | tslib.__extends(GraphQLWsLink, _super);
|
16 | function GraphQLWsLink(client) {
|
17 | var _this = _super.call(this) || this;
|
18 | _this.client = client;
|
19 | return _this;
|
20 | }
|
21 | GraphQLWsLink.prototype.request = function (operation) {
|
22 | var _this = this;
|
23 | return new utilities.Observable(function (observer) {
|
24 | return _this.client.subscribe(tslib.__assign(tslib.__assign({}, operation), { query: graphql.print(operation.query) }), {
|
25 | next: observer.next.bind(observer),
|
26 | complete: observer.complete.bind(observer),
|
27 | error: function (err) {
|
28 | if (err instanceof Error) {
|
29 | return observer.error(err);
|
30 | }
|
31 | if (isLikeCloseEvent(err)) {
|
32 | return observer.error(new Error("Socket closed with event ".concat(err.code, " ").concat(err.reason || "")));
|
33 | }
|
34 | return observer.error(new errors.ApolloError({
|
35 | graphQLErrors: Array.isArray(err) ? err : [err],
|
36 | }));
|
37 | },
|
38 | });
|
39 | });
|
40 | };
|
41 | return GraphQLWsLink;
|
42 | }(core.ApolloLink));
|
43 |
|
44 | exports.GraphQLWsLink = GraphQLWsLink;
|
45 |
|