@apollo/client 3.6.3 → 3.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apollo-client.cjs +123 -48
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +9 -10
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +2288 -0
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +10 -11
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +2 -2
- package/core/ObservableQuery.js.map +1 -1
- package/core/core.cjs +2 -2
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +2141 -0
- package/errors/errors.cjs.native.js +48 -0
- package/invariantErrorCodes.js +1 -1
- package/link/batch/batch.cjs.native.js +161 -0
- package/link/batch-http/batch-http.cjs.native.js +127 -0
- package/link/context/context.cjs.native.js +38 -0
- package/link/core/core.cjs.native.js +121 -0
- package/link/error/error.cjs.native.js +90 -0
- package/link/http/http.cjs.native.js +320 -0
- package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
- package/link/retry/retry.cjs.native.js +170 -0
- package/link/schema/schema.cjs.native.js +56 -0
- package/link/subscriptions/subscriptions.cjs.native.js +45 -0
- package/link/utils/utils.cjs.native.js +115 -0
- package/link/ws/ws.cjs.native.js +28 -0
- package/main.cjs.native.js +16 -0
- package/package.json +16 -17
- package/react/components/components.cjs.native.js +79 -0
- package/react/context/context.cjs.native.js +67 -0
- package/react/hoc/hoc.cjs.native.js +325 -0
- package/react/hooks/hooks.cjs +130 -43
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +623 -0
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +5 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.js +7 -7
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +2 -1
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +22 -6
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +17 -7
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSyncExternalStore.d.ts +4 -0
- package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
- package/react/hooks/useSyncExternalStore.js +48 -0
- package/react/hooks/useSyncExternalStore.js.map +1 -0
- package/react/parser/parser.cjs.native.js +103 -0
- package/react/react.cjs.native.js +22 -0
- package/react/ssr/ssr.cjs.native.js +150 -0
- package/testing/core/core.cjs.native.js +288 -0
- package/testing/testing.cjs.native.js +58 -0
- package/utilities/common/canUse.d.ts +2 -0
- package/utilities/common/canUse.d.ts.map +1 -1
- package/utilities/common/canUse.js +6 -2
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/mergeDeep.d.ts.map +1 -1
- package/utilities/common/mergeDeep.js +8 -11
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/globals/globals.cjs.native.js +56 -0
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js +5 -2
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js +9 -7
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/utilities.cjs +29 -22
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +1281 -0
- package/version.js +1 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
require('../utilities/globals');
|
|
7
|
+
var utilities = require('../utilities');
|
|
8
|
+
|
|
9
|
+
function isApolloError(err) {
|
|
10
|
+
return err.hasOwnProperty('graphQLErrors');
|
|
11
|
+
}
|
|
12
|
+
var generateErrorMessage = function (err) {
|
|
13
|
+
var message = '';
|
|
14
|
+
if (utilities.isNonEmptyArray(err.graphQLErrors) || utilities.isNonEmptyArray(err.clientErrors)) {
|
|
15
|
+
var errors = (err.graphQLErrors || [])
|
|
16
|
+
.concat(err.clientErrors || []);
|
|
17
|
+
errors.forEach(function (error) {
|
|
18
|
+
var errorMessage = error
|
|
19
|
+
? error.message
|
|
20
|
+
: 'Error message not found.';
|
|
21
|
+
message += "".concat(errorMessage, "\n");
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (err.networkError) {
|
|
25
|
+
message += "".concat(err.networkError.message, "\n");
|
|
26
|
+
}
|
|
27
|
+
message = message.replace(/\n$/, '');
|
|
28
|
+
return message;
|
|
29
|
+
};
|
|
30
|
+
var ApolloError = (function (_super) {
|
|
31
|
+
tslib.__extends(ApolloError, _super);
|
|
32
|
+
function ApolloError(_a) {
|
|
33
|
+
var graphQLErrors = _a.graphQLErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
|
|
34
|
+
var _this = _super.call(this, errorMessage) || this;
|
|
35
|
+
_this.graphQLErrors = graphQLErrors || [];
|
|
36
|
+
_this.clientErrors = clientErrors || [];
|
|
37
|
+
_this.networkError = networkError || null;
|
|
38
|
+
_this.message = errorMessage || generateErrorMessage(_this);
|
|
39
|
+
_this.extraInfo = extraInfo;
|
|
40
|
+
_this.__proto__ = ApolloError.prototype;
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
return ApolloError;
|
|
44
|
+
}(Error));
|
|
45
|
+
|
|
46
|
+
exports.ApolloError = ApolloError;
|
|
47
|
+
exports.isApolloError = isApolloError;
|
|
48
|
+
//# sourceMappingURL=errors.cjs.map
|
package/invariantErrorCodes.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// consult the @apollo/client/invariantErrorCodes.js file specific to
|
|
6
6
|
// your @apollo/client version. This file is not meant to be imported.
|
|
7
7
|
{
|
|
8
|
-
"@apollo/client version": "3.6.
|
|
8
|
+
"@apollo/client version": "3.6.6",
|
|
9
9
|
|
|
10
10
|
1: {
|
|
11
11
|
file: "@apollo/client/cache/inmemory/entityStore.js",
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var core = require('../core');
|
|
7
|
+
var utilities = require('../../utilities');
|
|
8
|
+
|
|
9
|
+
var OperationBatcher = (function () {
|
|
10
|
+
function OperationBatcher(_a) {
|
|
11
|
+
var batchDebounce = _a.batchDebounce, batchInterval = _a.batchInterval, batchMax = _a.batchMax, batchHandler = _a.batchHandler, batchKey = _a.batchKey;
|
|
12
|
+
this.batchesByKey = new Map();
|
|
13
|
+
this.batchDebounce = batchDebounce;
|
|
14
|
+
this.batchInterval = batchInterval;
|
|
15
|
+
this.batchMax = batchMax || 0;
|
|
16
|
+
this.batchHandler = batchHandler;
|
|
17
|
+
this.batchKey = batchKey || (function () { return ''; });
|
|
18
|
+
}
|
|
19
|
+
OperationBatcher.prototype.enqueueRequest = function (request) {
|
|
20
|
+
var _this = this;
|
|
21
|
+
var requestCopy = tslib.__assign(tslib.__assign({}, request), { next: [], error: [], complete: [], subscribers: new Set() });
|
|
22
|
+
var key = this.batchKey(request.operation);
|
|
23
|
+
if (!requestCopy.observable) {
|
|
24
|
+
requestCopy.observable = new utilities.Observable(function (observer) {
|
|
25
|
+
var batch = _this.batchesByKey.get(key);
|
|
26
|
+
if (!batch)
|
|
27
|
+
_this.batchesByKey.set(key, batch = new Set());
|
|
28
|
+
var isFirstEnqueuedRequest = batch.size === 0;
|
|
29
|
+
var isFirstSubscriber = requestCopy.subscribers.size === 0;
|
|
30
|
+
requestCopy.subscribers.add(observer);
|
|
31
|
+
if (isFirstSubscriber) {
|
|
32
|
+
batch.add(requestCopy);
|
|
33
|
+
}
|
|
34
|
+
if (observer.next) {
|
|
35
|
+
requestCopy.next.push(observer.next.bind(observer));
|
|
36
|
+
}
|
|
37
|
+
if (observer.error) {
|
|
38
|
+
requestCopy.error.push(observer.error.bind(observer));
|
|
39
|
+
}
|
|
40
|
+
if (observer.complete) {
|
|
41
|
+
requestCopy.complete.push(observer.complete.bind(observer));
|
|
42
|
+
}
|
|
43
|
+
if (isFirstEnqueuedRequest) {
|
|
44
|
+
_this.scheduleQueueConsumption(key);
|
|
45
|
+
}
|
|
46
|
+
else if (_this.batchDebounce) {
|
|
47
|
+
clearTimeout(_this.scheduledBatchTimer);
|
|
48
|
+
_this.scheduleQueueConsumption(key);
|
|
49
|
+
}
|
|
50
|
+
if (batch.size === _this.batchMax) {
|
|
51
|
+
_this.consumeQueue(key);
|
|
52
|
+
}
|
|
53
|
+
return function () {
|
|
54
|
+
var _a;
|
|
55
|
+
if (requestCopy.subscribers.delete(observer) &&
|
|
56
|
+
requestCopy.subscribers.size < 1) {
|
|
57
|
+
if (batch.delete(requestCopy) && batch.size < 1) {
|
|
58
|
+
clearTimeout(_this.scheduledBatchTimer);
|
|
59
|
+
_this.batchesByKey.delete(key);
|
|
60
|
+
(_a = batch.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return requestCopy.observable;
|
|
67
|
+
};
|
|
68
|
+
OperationBatcher.prototype.consumeQueue = function (key) {
|
|
69
|
+
if (key === void 0) { key = ''; }
|
|
70
|
+
var batch = this.batchesByKey.get(key);
|
|
71
|
+
this.batchesByKey.delete(key);
|
|
72
|
+
if (!batch || !batch.size) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var operations = [];
|
|
76
|
+
var forwards = [];
|
|
77
|
+
var observables = [];
|
|
78
|
+
var nexts = [];
|
|
79
|
+
var errors = [];
|
|
80
|
+
var completes = [];
|
|
81
|
+
batch.forEach(function (request) {
|
|
82
|
+
operations.push(request.operation);
|
|
83
|
+
forwards.push(request.forward);
|
|
84
|
+
observables.push(request.observable);
|
|
85
|
+
nexts.push(request.next);
|
|
86
|
+
errors.push(request.error);
|
|
87
|
+
completes.push(request.complete);
|
|
88
|
+
});
|
|
89
|
+
var batchedObservable = this.batchHandler(operations, forwards) || utilities.Observable.of();
|
|
90
|
+
var onError = function (error) {
|
|
91
|
+
errors.forEach(function (rejecters) {
|
|
92
|
+
if (rejecters) {
|
|
93
|
+
rejecters.forEach(function (e) { return e(error); });
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
batch.subscription = batchedObservable.subscribe({
|
|
98
|
+
next: function (results) {
|
|
99
|
+
if (!Array.isArray(results)) {
|
|
100
|
+
results = [results];
|
|
101
|
+
}
|
|
102
|
+
if (nexts.length !== results.length) {
|
|
103
|
+
var error = new Error("server returned results with length ".concat(results.length, ", expected length of ").concat(nexts.length));
|
|
104
|
+
error.result = results;
|
|
105
|
+
return onError(error);
|
|
106
|
+
}
|
|
107
|
+
results.forEach(function (result, index) {
|
|
108
|
+
if (nexts[index]) {
|
|
109
|
+
nexts[index].forEach(function (next) { return next(result); });
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
error: onError,
|
|
114
|
+
complete: function () {
|
|
115
|
+
completes.forEach(function (complete) {
|
|
116
|
+
if (complete) {
|
|
117
|
+
complete.forEach(function (c) { return c(); });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
return observables;
|
|
123
|
+
};
|
|
124
|
+
OperationBatcher.prototype.scheduleQueueConsumption = function (key) {
|
|
125
|
+
var _this = this;
|
|
126
|
+
this.scheduledBatchTimer = setTimeout(function () {
|
|
127
|
+
_this.consumeQueue(key);
|
|
128
|
+
}, this.batchInterval);
|
|
129
|
+
};
|
|
130
|
+
return OperationBatcher;
|
|
131
|
+
}());
|
|
132
|
+
|
|
133
|
+
var BatchLink = (function (_super) {
|
|
134
|
+
tslib.__extends(BatchLink, _super);
|
|
135
|
+
function BatchLink(fetchParams) {
|
|
136
|
+
var _this = _super.call(this) || this;
|
|
137
|
+
var _a = fetchParams || {}, batchDebounce = _a.batchDebounce, _b = _a.batchInterval, batchInterval = _b === void 0 ? 10 : _b, _c = _a.batchMax, batchMax = _c === void 0 ? 0 : _c, _d = _a.batchHandler, batchHandler = _d === void 0 ? function () { return null; } : _d, _e = _a.batchKey, batchKey = _e === void 0 ? function () { return ''; } : _e;
|
|
138
|
+
_this.batcher = new OperationBatcher({
|
|
139
|
+
batchDebounce: batchDebounce,
|
|
140
|
+
batchInterval: batchInterval,
|
|
141
|
+
batchMax: batchMax,
|
|
142
|
+
batchHandler: batchHandler,
|
|
143
|
+
batchKey: batchKey,
|
|
144
|
+
});
|
|
145
|
+
if (fetchParams.batchHandler.length <= 1) {
|
|
146
|
+
_this.request = function (operation) { return _this.batcher.enqueueRequest({ operation: operation }); };
|
|
147
|
+
}
|
|
148
|
+
return _this;
|
|
149
|
+
}
|
|
150
|
+
BatchLink.prototype.request = function (operation, forward) {
|
|
151
|
+
return this.batcher.enqueueRequest({
|
|
152
|
+
operation: operation,
|
|
153
|
+
forward: forward,
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
return BatchLink;
|
|
157
|
+
}(core.ApolloLink));
|
|
158
|
+
|
|
159
|
+
exports.BatchLink = BatchLink;
|
|
160
|
+
exports.OperationBatcher = OperationBatcher;
|
|
161
|
+
//# sourceMappingURL=batch.cjs.map
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var core = require('../core');
|
|
7
|
+
var utilities = require('../../utilities');
|
|
8
|
+
var utils = require('../utils');
|
|
9
|
+
var http = require('../http');
|
|
10
|
+
var batch = require('../batch');
|
|
11
|
+
|
|
12
|
+
var BatchHttpLink = (function (_super) {
|
|
13
|
+
tslib.__extends(BatchHttpLink, _super);
|
|
14
|
+
function BatchHttpLink(fetchParams) {
|
|
15
|
+
var _this = _super.call(this) || this;
|
|
16
|
+
var _a = fetchParams || {}, _b = _a.uri, uri = _b === void 0 ? '/graphql' : _b, fetcher = _a.fetch, _c = _a.print, print = _c === void 0 ? http.defaultPrinter : _c, includeExtensions = _a.includeExtensions, batchInterval = _a.batchInterval, batchDebounce = _a.batchDebounce, batchMax = _a.batchMax, batchKey = _a.batchKey, requestOptions = tslib.__rest(_a, ["uri", "fetch", "print", "includeExtensions", "batchInterval", "batchDebounce", "batchMax", "batchKey"]);
|
|
17
|
+
http.checkFetcher(fetcher);
|
|
18
|
+
if (!fetcher) {
|
|
19
|
+
fetcher = fetch;
|
|
20
|
+
}
|
|
21
|
+
var linkConfig = {
|
|
22
|
+
http: { includeExtensions: includeExtensions },
|
|
23
|
+
options: requestOptions.fetchOptions,
|
|
24
|
+
credentials: requestOptions.credentials,
|
|
25
|
+
headers: requestOptions.headers,
|
|
26
|
+
};
|
|
27
|
+
_this.batchDebounce = batchDebounce;
|
|
28
|
+
_this.batchInterval = batchInterval || 10;
|
|
29
|
+
_this.batchMax = batchMax || 10;
|
|
30
|
+
var batchHandler = function (operations) {
|
|
31
|
+
var chosenURI = http.selectURI(operations[0], uri);
|
|
32
|
+
var context = operations[0].getContext();
|
|
33
|
+
var clientAwarenessHeaders = {};
|
|
34
|
+
if (context.clientAwareness) {
|
|
35
|
+
var _a = context.clientAwareness, name_1 = _a.name, version = _a.version;
|
|
36
|
+
if (name_1) {
|
|
37
|
+
clientAwarenessHeaders['apollographql-client-name'] = name_1;
|
|
38
|
+
}
|
|
39
|
+
if (version) {
|
|
40
|
+
clientAwarenessHeaders['apollographql-client-version'] = version;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var contextConfig = {
|
|
44
|
+
http: context.http,
|
|
45
|
+
options: context.fetchOptions,
|
|
46
|
+
credentials: context.credentials,
|
|
47
|
+
headers: tslib.__assign(tslib.__assign({}, clientAwarenessHeaders), context.headers),
|
|
48
|
+
};
|
|
49
|
+
var optsAndBody = operations.map(function (operation) {
|
|
50
|
+
return http.selectHttpOptionsAndBodyInternal(operation, print, http.fallbackHttpConfig, linkConfig, contextConfig);
|
|
51
|
+
});
|
|
52
|
+
var loadedBody = optsAndBody.map(function (_a) {
|
|
53
|
+
var body = _a.body;
|
|
54
|
+
return body;
|
|
55
|
+
});
|
|
56
|
+
var options = optsAndBody[0].options;
|
|
57
|
+
if (options.method === 'GET') {
|
|
58
|
+
return utils.fromError(new Error('apollo-link-batch-http does not support GET requests'));
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
options.body = http.serializeFetchParameter(loadedBody, 'Payload');
|
|
62
|
+
}
|
|
63
|
+
catch (parseError) {
|
|
64
|
+
return utils.fromError(parseError);
|
|
65
|
+
}
|
|
66
|
+
var controller;
|
|
67
|
+
if (!options.signal) {
|
|
68
|
+
var _b = http.createSignalIfSupported(), _controller = _b.controller, signal = _b.signal;
|
|
69
|
+
controller = _controller;
|
|
70
|
+
if (controller)
|
|
71
|
+
options.signal = signal;
|
|
72
|
+
}
|
|
73
|
+
return new utilities.Observable(function (observer) {
|
|
74
|
+
fetcher(chosenURI, options)
|
|
75
|
+
.then(function (response) {
|
|
76
|
+
operations.forEach(function (operation) { return operation.setContext({ response: response }); });
|
|
77
|
+
return response;
|
|
78
|
+
})
|
|
79
|
+
.then(http.parseAndCheckHttpResponse(operations))
|
|
80
|
+
.then(function (result) {
|
|
81
|
+
observer.next(result);
|
|
82
|
+
observer.complete();
|
|
83
|
+
return result;
|
|
84
|
+
})
|
|
85
|
+
.catch(function (err) {
|
|
86
|
+
if (err.name === 'AbortError')
|
|
87
|
+
return;
|
|
88
|
+
if (err.result && err.result.errors && err.result.data) {
|
|
89
|
+
observer.next(err.result);
|
|
90
|
+
}
|
|
91
|
+
observer.error(err);
|
|
92
|
+
});
|
|
93
|
+
return function () {
|
|
94
|
+
if (controller)
|
|
95
|
+
controller.abort();
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
batchKey =
|
|
100
|
+
batchKey ||
|
|
101
|
+
(function (operation) {
|
|
102
|
+
var context = operation.getContext();
|
|
103
|
+
var contextConfig = {
|
|
104
|
+
http: context.http,
|
|
105
|
+
options: context.fetchOptions,
|
|
106
|
+
credentials: context.credentials,
|
|
107
|
+
headers: context.headers,
|
|
108
|
+
};
|
|
109
|
+
return http.selectURI(operation, uri) + JSON.stringify(contextConfig);
|
|
110
|
+
});
|
|
111
|
+
_this.batcher = new batch.BatchLink({
|
|
112
|
+
batchDebounce: _this.batchDebounce,
|
|
113
|
+
batchInterval: _this.batchInterval,
|
|
114
|
+
batchMax: _this.batchMax,
|
|
115
|
+
batchKey: batchKey,
|
|
116
|
+
batchHandler: batchHandler,
|
|
117
|
+
});
|
|
118
|
+
return _this;
|
|
119
|
+
}
|
|
120
|
+
BatchHttpLink.prototype.request = function (operation) {
|
|
121
|
+
return this.batcher.request(operation);
|
|
122
|
+
};
|
|
123
|
+
return BatchHttpLink;
|
|
124
|
+
}(core.ApolloLink));
|
|
125
|
+
|
|
126
|
+
exports.BatchHttpLink = BatchHttpLink;
|
|
127
|
+
//# sourceMappingURL=batch-http.cjs.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var core = require('../core');
|
|
7
|
+
var utilities = require('../../utilities');
|
|
8
|
+
|
|
9
|
+
function setContext(setter) {
|
|
10
|
+
return new core.ApolloLink(function (operation, forward) {
|
|
11
|
+
var request = tslib.__rest(operation, []);
|
|
12
|
+
return new utilities.Observable(function (observer) {
|
|
13
|
+
var handle;
|
|
14
|
+
var closed = false;
|
|
15
|
+
Promise.resolve(request)
|
|
16
|
+
.then(function (req) { return setter(req, operation.getContext()); })
|
|
17
|
+
.then(operation.setContext)
|
|
18
|
+
.then(function () {
|
|
19
|
+
if (closed)
|
|
20
|
+
return;
|
|
21
|
+
handle = forward(operation).subscribe({
|
|
22
|
+
next: observer.next.bind(observer),
|
|
23
|
+
error: observer.error.bind(observer),
|
|
24
|
+
complete: observer.complete.bind(observer),
|
|
25
|
+
});
|
|
26
|
+
})
|
|
27
|
+
.catch(observer.error.bind(observer));
|
|
28
|
+
return function () {
|
|
29
|
+
closed = true;
|
|
30
|
+
if (handle)
|
|
31
|
+
handle.unsubscribe();
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.setContext = setContext;
|
|
38
|
+
//# sourceMappingURL=context.cjs.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var globals = require('../../utilities/globals');
|
|
6
|
+
var tslib = require('tslib');
|
|
7
|
+
var utilities = require('../../utilities');
|
|
8
|
+
var utils = require('../utils');
|
|
9
|
+
|
|
10
|
+
function passthrough(op, forward) {
|
|
11
|
+
return (forward ? forward(op) : utilities.Observable.of());
|
|
12
|
+
}
|
|
13
|
+
function toLink(handler) {
|
|
14
|
+
return typeof handler === 'function' ? new ApolloLink(handler) : handler;
|
|
15
|
+
}
|
|
16
|
+
function isTerminating(link) {
|
|
17
|
+
return link.request.length <= 1;
|
|
18
|
+
}
|
|
19
|
+
var LinkError = (function (_super) {
|
|
20
|
+
tslib.__extends(LinkError, _super);
|
|
21
|
+
function LinkError(message, link) {
|
|
22
|
+
var _this = _super.call(this, message) || this;
|
|
23
|
+
_this.link = link;
|
|
24
|
+
return _this;
|
|
25
|
+
}
|
|
26
|
+
return LinkError;
|
|
27
|
+
}(Error));
|
|
28
|
+
var ApolloLink = (function () {
|
|
29
|
+
function ApolloLink(request) {
|
|
30
|
+
if (request)
|
|
31
|
+
this.request = request;
|
|
32
|
+
}
|
|
33
|
+
ApolloLink.empty = function () {
|
|
34
|
+
return new ApolloLink(function () { return utilities.Observable.of(); });
|
|
35
|
+
};
|
|
36
|
+
ApolloLink.from = function (links) {
|
|
37
|
+
if (links.length === 0)
|
|
38
|
+
return ApolloLink.empty();
|
|
39
|
+
return links.map(toLink).reduce(function (x, y) { return x.concat(y); });
|
|
40
|
+
};
|
|
41
|
+
ApolloLink.split = function (test, left, right) {
|
|
42
|
+
var leftLink = toLink(left);
|
|
43
|
+
var rightLink = toLink(right || new ApolloLink(passthrough));
|
|
44
|
+
if (isTerminating(leftLink) && isTerminating(rightLink)) {
|
|
45
|
+
return new ApolloLink(function (operation) {
|
|
46
|
+
return test(operation)
|
|
47
|
+
? leftLink.request(operation) || utilities.Observable.of()
|
|
48
|
+
: rightLink.request(operation) || utilities.Observable.of();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return new ApolloLink(function (operation, forward) {
|
|
53
|
+
return test(operation)
|
|
54
|
+
? leftLink.request(operation, forward) || utilities.Observable.of()
|
|
55
|
+
: rightLink.request(operation, forward) || utilities.Observable.of();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
ApolloLink.execute = function (link, operation) {
|
|
60
|
+
return (link.request(utils.createOperation(operation.context, utils.transformOperation(utils.validateOperation(operation)))) || utilities.Observable.of());
|
|
61
|
+
};
|
|
62
|
+
ApolloLink.concat = function (first, second) {
|
|
63
|
+
var firstLink = toLink(first);
|
|
64
|
+
if (isTerminating(firstLink)) {
|
|
65
|
+
__DEV__ && globals.invariant.warn(new LinkError("You are calling concat on a terminating link, which will have no effect", firstLink));
|
|
66
|
+
return firstLink;
|
|
67
|
+
}
|
|
68
|
+
var nextLink = toLink(second);
|
|
69
|
+
if (isTerminating(nextLink)) {
|
|
70
|
+
return new ApolloLink(function (operation) {
|
|
71
|
+
return firstLink.request(operation, function (op) { return nextLink.request(op) || utilities.Observable.of(); }) || utilities.Observable.of();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return new ApolloLink(function (operation, forward) {
|
|
76
|
+
return (firstLink.request(operation, function (op) {
|
|
77
|
+
return nextLink.request(op, forward) || utilities.Observable.of();
|
|
78
|
+
}) || utilities.Observable.of());
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
ApolloLink.prototype.split = function (test, left, right) {
|
|
83
|
+
return this.concat(ApolloLink.split(test, left, right || new ApolloLink(passthrough)));
|
|
84
|
+
};
|
|
85
|
+
ApolloLink.prototype.concat = function (next) {
|
|
86
|
+
return ApolloLink.concat(this, next);
|
|
87
|
+
};
|
|
88
|
+
ApolloLink.prototype.request = function (operation, forward) {
|
|
89
|
+
throw __DEV__ ? new globals.InvariantError('request is not implemented') : new globals.InvariantError(19);
|
|
90
|
+
};
|
|
91
|
+
ApolloLink.prototype.onError = function (error, observer) {
|
|
92
|
+
if (observer && observer.error) {
|
|
93
|
+
observer.error(error);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
throw error;
|
|
97
|
+
};
|
|
98
|
+
ApolloLink.prototype.setOnError = function (fn) {
|
|
99
|
+
this.onError = fn;
|
|
100
|
+
return this;
|
|
101
|
+
};
|
|
102
|
+
return ApolloLink;
|
|
103
|
+
}());
|
|
104
|
+
|
|
105
|
+
var empty = ApolloLink.empty;
|
|
106
|
+
|
|
107
|
+
var from = ApolloLink.from;
|
|
108
|
+
|
|
109
|
+
var split = ApolloLink.split;
|
|
110
|
+
|
|
111
|
+
var concat = ApolloLink.concat;
|
|
112
|
+
|
|
113
|
+
var execute = ApolloLink.execute;
|
|
114
|
+
|
|
115
|
+
exports.ApolloLink = ApolloLink;
|
|
116
|
+
exports.concat = concat;
|
|
117
|
+
exports.empty = empty;
|
|
118
|
+
exports.execute = execute;
|
|
119
|
+
exports.from = from;
|
|
120
|
+
exports.split = split;
|
|
121
|
+
//# sourceMappingURL=core.cjs.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var utilities = require('../../utilities');
|
|
7
|
+
var core = require('../core');
|
|
8
|
+
|
|
9
|
+
function onError(errorHandler) {
|
|
10
|
+
return new core.ApolloLink(function (operation, forward) {
|
|
11
|
+
return new utilities.Observable(function (observer) {
|
|
12
|
+
var sub;
|
|
13
|
+
var retriedSub;
|
|
14
|
+
var retriedResult;
|
|
15
|
+
try {
|
|
16
|
+
sub = forward(operation).subscribe({
|
|
17
|
+
next: function (result) {
|
|
18
|
+
if (result.errors) {
|
|
19
|
+
retriedResult = errorHandler({
|
|
20
|
+
graphQLErrors: result.errors,
|
|
21
|
+
response: result,
|
|
22
|
+
operation: operation,
|
|
23
|
+
forward: forward,
|
|
24
|
+
});
|
|
25
|
+
if (retriedResult) {
|
|
26
|
+
retriedSub = retriedResult.subscribe({
|
|
27
|
+
next: observer.next.bind(observer),
|
|
28
|
+
error: observer.error.bind(observer),
|
|
29
|
+
complete: observer.complete.bind(observer),
|
|
30
|
+
});
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
observer.next(result);
|
|
35
|
+
},
|
|
36
|
+
error: function (networkError) {
|
|
37
|
+
retriedResult = errorHandler({
|
|
38
|
+
operation: operation,
|
|
39
|
+
networkError: networkError,
|
|
40
|
+
graphQLErrors: networkError &&
|
|
41
|
+
networkError.result &&
|
|
42
|
+
networkError.result.errors,
|
|
43
|
+
forward: forward,
|
|
44
|
+
});
|
|
45
|
+
if (retriedResult) {
|
|
46
|
+
retriedSub = retriedResult.subscribe({
|
|
47
|
+
next: observer.next.bind(observer),
|
|
48
|
+
error: observer.error.bind(observer),
|
|
49
|
+
complete: observer.complete.bind(observer),
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
observer.error(networkError);
|
|
54
|
+
},
|
|
55
|
+
complete: function () {
|
|
56
|
+
if (!retriedResult) {
|
|
57
|
+
observer.complete.bind(observer)();
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
errorHandler({ networkError: e, operation: operation, forward: forward });
|
|
64
|
+
observer.error(e);
|
|
65
|
+
}
|
|
66
|
+
return function () {
|
|
67
|
+
if (sub)
|
|
68
|
+
sub.unsubscribe();
|
|
69
|
+
if (retriedSub)
|
|
70
|
+
sub.unsubscribe();
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
var ErrorLink = (function (_super) {
|
|
76
|
+
tslib.__extends(ErrorLink, _super);
|
|
77
|
+
function ErrorLink(errorHandler) {
|
|
78
|
+
var _this = _super.call(this) || this;
|
|
79
|
+
_this.link = onError(errorHandler);
|
|
80
|
+
return _this;
|
|
81
|
+
}
|
|
82
|
+
ErrorLink.prototype.request = function (operation, forward) {
|
|
83
|
+
return this.link.request(operation, forward);
|
|
84
|
+
};
|
|
85
|
+
return ErrorLink;
|
|
86
|
+
}(core.ApolloLink));
|
|
87
|
+
|
|
88
|
+
exports.ErrorLink = ErrorLink;
|
|
89
|
+
exports.onError = onError;
|
|
90
|
+
//# sourceMappingURL=error.cjs.map
|