@apollo/client 3.5.3 → 3.6.0-beta.2
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 +95 -133
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/core.cjs +5 -5
- package/core/core.cjs.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/main.cjs +4 -4
- package/package.json +15 -10
- package/react/components/components.cjs +3 -3
- package/react/context/context.cjs +3 -3
- package/react/hoc/hoc.cjs +4 -4
- package/react/hooks/hooks.cjs +89 -127
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +7 -4
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +82 -123
- package/react/hooks/useQuery.js.map +1 -1
- package/react/react.cjs +2 -2
- package/react/ssr/RenderPromises.d.ts +2 -2
- package/react/ssr/RenderPromises.d.ts.map +1 -1
- package/react/ssr/RenderPromises.js +5 -7
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/ssr.cjs +8 -10
- package/react/ssr/ssr.cjs.map +1 -1
- package/testing/testing.cjs +5 -5
- package/utilities/globals/fix-graphql.js +1 -1
- package/version.js +1 -1
package/apollo-client.cjs
CHANGED
|
@@ -13,16 +13,17 @@ var context = require('@wry/context');
|
|
|
13
13
|
var trie = require('@wry/trie');
|
|
14
14
|
var graphqlTag = require('graphql-tag');
|
|
15
15
|
var React = require('react');
|
|
16
|
+
var shim = require('use-sync-external-store/shim');
|
|
16
17
|
|
|
17
18
|
function _interopNamespace(e) {
|
|
18
19
|
if (e && e.__esModule) return e;
|
|
19
20
|
var n = Object.create(null);
|
|
20
21
|
if (e) {
|
|
21
|
-
|
|
22
|
+
for (var k in e) {
|
|
22
23
|
n[k] = e[k];
|
|
23
|
-
}
|
|
24
|
+
}
|
|
24
25
|
}
|
|
25
|
-
n[
|
|
26
|
+
n["default"] = e;
|
|
26
27
|
return Object.freeze(n);
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -1291,7 +1292,7 @@ var concat = ApolloLink.concat;
|
|
|
1291
1292
|
|
|
1292
1293
|
var execute = ApolloLink.execute;
|
|
1293
1294
|
|
|
1294
|
-
var version = '3.
|
|
1295
|
+
var version = '3.6.0-beta.2';
|
|
1295
1296
|
|
|
1296
1297
|
var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
1297
1298
|
function parseAndCheckHttpResponse(operations) {
|
|
@@ -6045,6 +6046,12 @@ function useQuery(query, options) {
|
|
|
6045
6046
|
var context = React.useContext(getApolloContext());
|
|
6046
6047
|
var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
|
|
6047
6048
|
verifyDocumentType(query, exports.DocumentType.Query);
|
|
6049
|
+
var ref = React.useRef({
|
|
6050
|
+
client: client,
|
|
6051
|
+
query: query,
|
|
6052
|
+
options: options,
|
|
6053
|
+
watchQueryOptions: createWatchQueryOptions(query, options),
|
|
6054
|
+
});
|
|
6048
6055
|
var _b = React.useState(function () {
|
|
6049
6056
|
var watchQueryOptions = createWatchQueryOptions(query, options);
|
|
6050
6057
|
var obsQuery = null;
|
|
@@ -6084,114 +6091,96 @@ function useQuery(query, options) {
|
|
|
6084
6091
|
}
|
|
6085
6092
|
return obsQuery;
|
|
6086
6093
|
}), obsQuery = _b[0], setObsQuery = _b[1];
|
|
6087
|
-
var _c = React.useState(function () {
|
|
6088
|
-
var _a, _b;
|
|
6089
|
-
var result = obsQuery.getCurrentResult();
|
|
6090
|
-
if (!result.loading && options) {
|
|
6091
|
-
if (result.error) {
|
|
6092
|
-
(_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
|
|
6093
|
-
}
|
|
6094
|
-
else if (result.data) {
|
|
6095
|
-
(_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
|
|
6096
|
-
}
|
|
6097
|
-
}
|
|
6098
|
-
return result;
|
|
6099
|
-
}), result = _c[0], setResult = _c[1];
|
|
6100
|
-
var ref = React.useRef({
|
|
6101
|
-
client: client,
|
|
6102
|
-
query: query,
|
|
6103
|
-
options: options,
|
|
6104
|
-
result: result,
|
|
6105
|
-
previousData: void 0,
|
|
6106
|
-
watchQueryOptions: createWatchQueryOptions(query, options),
|
|
6107
|
-
});
|
|
6108
6094
|
React.useEffect(function () {
|
|
6109
|
-
var _a, _b;
|
|
6110
6095
|
var watchQueryOptions = createWatchQueryOptions(query, options);
|
|
6111
|
-
var nextResult;
|
|
6112
6096
|
if (ref.current.client !== client || !equality.equal(ref.current.query, query)) {
|
|
6113
6097
|
var obsQuery_1 = client.watchQuery(watchQueryOptions);
|
|
6114
6098
|
setObsQuery(obsQuery_1);
|
|
6115
|
-
nextResult = obsQuery_1.getCurrentResult();
|
|
6116
6099
|
}
|
|
6117
6100
|
else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
|
|
6118
|
-
obsQuery.setOptions(watchQueryOptions)
|
|
6119
|
-
|
|
6120
|
-
ref.current.watchQueryOptions = watchQueryOptions;
|
|
6121
|
-
}
|
|
6122
|
-
if (nextResult) {
|
|
6123
|
-
var previousResult = ref.current.result;
|
|
6124
|
-
if (previousResult.data) {
|
|
6125
|
-
ref.current.previousData = previousResult.data;
|
|
6126
|
-
}
|
|
6127
|
-
setResult(ref.current.result = nextResult);
|
|
6128
|
-
if (!nextResult.loading && options) {
|
|
6129
|
-
if (!result.loading) {
|
|
6130
|
-
if (result.error) {
|
|
6131
|
-
(_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
|
|
6132
|
-
}
|
|
6133
|
-
else if (result.data) {
|
|
6134
|
-
(_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
|
|
6135
|
-
}
|
|
6136
|
-
}
|
|
6137
|
-
}
|
|
6101
|
+
obsQuery.setOptions(watchQueryOptions);
|
|
6102
|
+
setObsQuery(obsQuery);
|
|
6138
6103
|
}
|
|
6139
|
-
Object.assign(ref.current, {
|
|
6104
|
+
Object.assign(ref.current, {
|
|
6105
|
+
client: client,
|
|
6106
|
+
query: query,
|
|
6107
|
+
options: options,
|
|
6108
|
+
watchQueryOptions: watchQueryOptions,
|
|
6109
|
+
});
|
|
6140
6110
|
}, [obsQuery, client, query, options]);
|
|
6141
|
-
React.
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
var result = obsQuery.getCurrentResult();
|
|
6150
|
-
if (previousResult &&
|
|
6151
|
-
previousResult.loading === result.loading &&
|
|
6152
|
-
previousResult.networkStatus === result.networkStatus &&
|
|
6153
|
-
equality.equal(previousResult.data, result.data)) {
|
|
6154
|
-
return;
|
|
6155
|
-
}
|
|
6156
|
-
if (previousResult.data) {
|
|
6157
|
-
ref.current.previousData = previousResult.data;
|
|
6158
|
-
}
|
|
6159
|
-
setResult(ref.current.result = result);
|
|
6160
|
-
if (!result.loading) {
|
|
6161
|
-
(_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
|
|
6162
|
-
}
|
|
6163
|
-
}
|
|
6164
|
-
function onError(error) {
|
|
6165
|
-
var _a, _b;
|
|
6166
|
-
var last = obsQuery["last"];
|
|
6167
|
-
subscription.unsubscribe();
|
|
6168
|
-
try {
|
|
6111
|
+
var _c = React.useMemo(function () {
|
|
6112
|
+
var previousResult;
|
|
6113
|
+
var subscribe = function (forceUpdate) {
|
|
6114
|
+
var subscription = obsQuery.subscribe(forceUpdate, onError);
|
|
6115
|
+
function onError(error) {
|
|
6116
|
+
forceUpdate();
|
|
6117
|
+
subscription.unsubscribe();
|
|
6118
|
+
var last = obsQuery["last"];
|
|
6169
6119
|
obsQuery.resetLastResults();
|
|
6170
|
-
|
|
6171
|
-
}
|
|
6172
|
-
finally {
|
|
6120
|
+
obsQuery.subscribe(forceUpdate, onError);
|
|
6173
6121
|
obsQuery["last"] = last;
|
|
6122
|
+
if (!error.hasOwnProperty('graphQLErrors')) {
|
|
6123
|
+
throw error;
|
|
6124
|
+
}
|
|
6174
6125
|
}
|
|
6175
|
-
|
|
6176
|
-
|
|
6126
|
+
return function () {
|
|
6127
|
+
subscription.unsubscribe();
|
|
6128
|
+
};
|
|
6129
|
+
};
|
|
6130
|
+
var getSnapshot = function () {
|
|
6131
|
+
var result = obsQuery.getCurrentResult();
|
|
6132
|
+
if (result.errors && result.errors.length) {
|
|
6133
|
+
result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
|
|
6134
|
+
}
|
|
6135
|
+
if (!previousResult ||
|
|
6136
|
+
previousResult.loading !== result.loading ||
|
|
6137
|
+
previousResult.networkStatus !== result.networkStatus ||
|
|
6138
|
+
!equality.equal(previousResult.data, result.data) ||
|
|
6139
|
+
!equality.equal(previousResult.error, result.error)) {
|
|
6140
|
+
if (previousResult) {
|
|
6141
|
+
result = tslib.__assign(tslib.__assign({}, result), { previousData: previousResult.data || previousResult.previousData });
|
|
6142
|
+
}
|
|
6143
|
+
previousResult = result;
|
|
6177
6144
|
}
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6145
|
+
return previousResult;
|
|
6146
|
+
};
|
|
6147
|
+
return [subscribe, getSnapshot];
|
|
6148
|
+
}, [obsQuery]), subscribe = _c[0], getSnapshot = _c[1];
|
|
6149
|
+
var obsQueryMethods = React.useMemo(function () { return ({
|
|
6150
|
+
refetch: obsQuery.refetch.bind(obsQuery),
|
|
6151
|
+
fetchMore: obsQuery.fetchMore.bind(obsQuery),
|
|
6152
|
+
updateQuery: obsQuery.updateQuery.bind(obsQuery),
|
|
6153
|
+
startPolling: obsQuery.startPolling.bind(obsQuery),
|
|
6154
|
+
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
6155
|
+
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
6156
|
+
}); }, [obsQuery]);
|
|
6157
|
+
var result = shim.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
6158
|
+
React.useEffect(function () {
|
|
6159
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6160
|
+
if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) ||
|
|
6161
|
+
((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) === 'standby') {
|
|
6162
|
+
return;
|
|
6163
|
+
}
|
|
6164
|
+
if (!result.loading) {
|
|
6165
|
+
if (result.error) {
|
|
6166
|
+
(_d = (_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.onError) === null || _d === void 0 ? void 0 : _d.call(_c, result.error);
|
|
6167
|
+
}
|
|
6168
|
+
else if (result.data) {
|
|
6169
|
+
(_f = (_e = ref.current.options) === null || _e === void 0 ? void 0 : _e.onCompleted) === null || _f === void 0 ? void 0 : _f.call(_e, result.data);
|
|
6188
6170
|
}
|
|
6189
6171
|
}
|
|
6190
|
-
|
|
6191
|
-
}, [obsQuery, context.renderPromises, client.disableNetworkFetches]);
|
|
6172
|
+
}, [result]);
|
|
6192
6173
|
var partial;
|
|
6193
6174
|
(_a = result, partial = _a.partial, result = tslib.__rest(_a, ["partial"]));
|
|
6194
|
-
{
|
|
6175
|
+
if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
|
|
6176
|
+
result = {
|
|
6177
|
+
loading: false,
|
|
6178
|
+
data: void 0,
|
|
6179
|
+
error: void 0,
|
|
6180
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
6181
|
+
};
|
|
6182
|
+
}
|
|
6183
|
+
else {
|
|
6195
6184
|
if (partial &&
|
|
6196
6185
|
(options === null || options === void 0 ? void 0 : options.partialRefetch) &&
|
|
6197
6186
|
!result.loading &&
|
|
@@ -6200,42 +6189,12 @@ function useQuery(query, options) {
|
|
|
6200
6189
|
result = tslib.__assign(tslib.__assign({}, result), { loading: true, networkStatus: exports.NetworkStatus.refetch });
|
|
6201
6190
|
obsQuery.refetch();
|
|
6202
6191
|
}
|
|
6203
|
-
if (context.renderPromises &&
|
|
6204
|
-
(
|
|
6205
|
-
|
|
6206
|
-
result.loading) {
|
|
6207
|
-
obsQuery.setOptions(createWatchQueryOptions(query, options)).catch(function () { });
|
|
6192
|
+
if (context.renderPromises && (options === null || options === void 0 ? void 0 : options.ssr) !== false && result.loading) {
|
|
6193
|
+
obsQuery.setOptions(createWatchQueryOptions(query, options))
|
|
6194
|
+
.catch(function () { });
|
|
6208
6195
|
}
|
|
6209
6196
|
}
|
|
6210
|
-
|
|
6211
|
-
(options === null || options === void 0 ? void 0 : options.ssr) === false) {
|
|
6212
|
-
result = ref.current.result = {
|
|
6213
|
-
loading: true,
|
|
6214
|
-
data: void 0,
|
|
6215
|
-
error: void 0,
|
|
6216
|
-
networkStatus: exports.NetworkStatus.loading,
|
|
6217
|
-
};
|
|
6218
|
-
}
|
|
6219
|
-
else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
|
|
6220
|
-
result = {
|
|
6221
|
-
loading: false,
|
|
6222
|
-
data: void 0,
|
|
6223
|
-
error: void 0,
|
|
6224
|
-
networkStatus: exports.NetworkStatus.ready,
|
|
6225
|
-
};
|
|
6226
|
-
}
|
|
6227
|
-
if (result.errors && result.errors.length) {
|
|
6228
|
-
result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
|
|
6229
|
-
}
|
|
6230
|
-
var obsQueryFields = React.useMemo(function () { return ({
|
|
6231
|
-
refetch: obsQuery.refetch.bind(obsQuery),
|
|
6232
|
-
fetchMore: obsQuery.fetchMore.bind(obsQuery),
|
|
6233
|
-
updateQuery: obsQuery.updateQuery.bind(obsQuery),
|
|
6234
|
-
startPolling: obsQuery.startPolling.bind(obsQuery),
|
|
6235
|
-
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
6236
|
-
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
6237
|
-
}); }, [obsQuery]);
|
|
6238
|
-
return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryFields), { variables: obsQuery.variables, client: client, called: true, previousData: ref.current.previousData }), result);
|
|
6197
|
+
return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryMethods), { variables: obsQuery.variables, client: client, called: true }), result);
|
|
6239
6198
|
}
|
|
6240
6199
|
function createWatchQueryOptions(query, options) {
|
|
6241
6200
|
var _a;
|
|
@@ -6353,13 +6312,13 @@ function useMutation(mutation, options) {
|
|
|
6353
6312
|
var mutationId = ++ref.current.mutationId;
|
|
6354
6313
|
var clientOptions = mergeOptions(baseOptions, executeOptions);
|
|
6355
6314
|
return client.mutate(clientOptions).then(function (response) {
|
|
6356
|
-
var _a;
|
|
6315
|
+
var _a, _b;
|
|
6357
6316
|
var data = response.data, errors = response.errors;
|
|
6358
6317
|
var error = errors && errors.length > 0
|
|
6359
6318
|
? new ApolloError({ graphQLErrors: errors })
|
|
6360
6319
|
: void 0;
|
|
6361
6320
|
if (mutationId === ref.current.mutationId &&
|
|
6362
|
-
!
|
|
6321
|
+
!clientOptions.ignoreResults) {
|
|
6363
6322
|
var result_1 = {
|
|
6364
6323
|
called: true,
|
|
6365
6324
|
loading: false,
|
|
@@ -6372,8 +6331,10 @@ function useMutation(mutation, options) {
|
|
|
6372
6331
|
}
|
|
6373
6332
|
}
|
|
6374
6333
|
(_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
|
|
6334
|
+
(_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
|
|
6375
6335
|
return response;
|
|
6376
6336
|
}).catch(function (error) {
|
|
6337
|
+
var _a, _b;
|
|
6377
6338
|
if (mutationId === ref.current.mutationId &&
|
|
6378
6339
|
ref.current.isMounted) {
|
|
6379
6340
|
var result_2 = {
|
|
@@ -6387,8 +6348,9 @@ function useMutation(mutation, options) {
|
|
|
6387
6348
|
setResult(ref.current.result = result_2);
|
|
6388
6349
|
}
|
|
6389
6350
|
}
|
|
6390
|
-
if (baseOptions.onError) {
|
|
6391
|
-
baseOptions.onError(error);
|
|
6351
|
+
if (baseOptions.onError || clientOptions.onError) {
|
|
6352
|
+
(_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
|
|
6353
|
+
(_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
|
|
6392
6354
|
return { data: void 0, errors: error };
|
|
6393
6355
|
}
|
|
6394
6356
|
throw error;
|