UNPKG

1.71 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var tslib = require('tslib');
6var graphql = require('graphql');
7var core = require('../core');
8var utilities = require('../../utilities');
9var errors = require('../../errors');
10
11function isLikeCloseEvent(val) {
12 return utilities.isNonNullObject(val) && 'code' in val && 'reason' in val;
13}
14var 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
44exports.GraphQLWsLink = GraphQLWsLink;
45//# sourceMappingURL=subscriptions.cjs.map