@apollo/client 3.7.3 → 3.7.5
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/README.md +8 -7
- package/apollo-client.cjs +63 -25
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +5 -0
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +6 -1
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +6 -1
- package/core/types.d.ts +2 -1
- package/core/types.d.ts.map +1 -1
- package/core/types.js +1 -0
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.d.ts +2 -2
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/link/context/index.d.ts +2 -1
- package/link/context/index.d.ts.map +1 -1
- package/link/context/index.js.map +1 -1
- package/link/core/types.d.ts +5 -4
- package/link/core/types.d.ts.map +1 -1
- package/link/core/types.js.map +1 -1
- package/link/http/createHttpLink.d.ts.map +1 -1
- package/link/http/createHttpLink.js +1 -0
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/http.cjs +4 -1
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +4 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +2 -2
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js +3 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/package.json +19 -15
- package/react/hooks/hooks.cjs +53 -23
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +53 -23
- package/react/hooks/useFragment.d.ts +2 -1
- package/react/hooks/useFragment.d.ts.map +1 -1
- package/react/hooks/useFragment.js +9 -8
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +19 -4
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts.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 +19 -5
- package/react/hooks/useQuery.js.map +1 -1
- package/testing/core/core.cjs +17 -0
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +17 -0
- package/testing/core/index.d.ts +1 -0
- package/testing/core/index.d.ts.map +1 -1
- package/testing/core/index.js +1 -0
- package/testing/core/index.js.map +1 -1
- package/testing/core/wait.d.ts +3 -0
- package/testing/core/wait.d.ts.map +1 -0
- package/testing/core/wait.js +16 -0
- package/testing/core/wait.js.map +1 -0
- package/version.js +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
[](https://badge.fury.io/js/%40apollo%2Fclient)
|
|
6
6
|
[](https://circleci.com/gh/apollographql/apollo-client)
|
|
7
7
|
[](https://community.apollographql.com)
|
|
8
|
+
[](https://discord.gg/graphos)
|
|
8
9
|
|
|
9
10
|
Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components that fetch data via GraphQL.
|
|
10
11
|
|
|
@@ -21,13 +22,13 @@ Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apo
|
|
|
21
22
|
|
|
22
23
|
## Maintainers
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
|Name|Username|
|
|
26
|
+
|---|---|
|
|
27
|
+
|Ben Newman|[@benjamn](https://github.com/benjamn)|
|
|
28
|
+
|Alessia Bellisario|[@alessbell](https://github.com/alessbell)|
|
|
29
|
+
|Jeff Auriemma|[@bignimbus](https://github.com/bignimbus)|
|
|
30
|
+
|Hugh Willson|[@hwillson](https://github.com/hwillson)|
|
|
31
|
+
|Jerel Miller|[@jerelmiller](https://github.com/jerelmiller)|
|
|
31
32
|
|
|
32
33
|
## Who is Apollo?
|
|
33
34
|
|
package/apollo-client.cjs
CHANGED
|
@@ -1345,7 +1345,7 @@ var concat = ApolloLink.concat;
|
|
|
1345
1345
|
|
|
1346
1346
|
var execute = ApolloLink.execute;
|
|
1347
1347
|
|
|
1348
|
-
var version = '3.7.
|
|
1348
|
+
var version = '3.7.5';
|
|
1349
1349
|
|
|
1350
1350
|
function isNodeResponse(value) {
|
|
1351
1351
|
return !!value.body;
|
|
@@ -1709,7 +1709,9 @@ function selectHttpOptionsAndBodyInternal(operation, printer) {
|
|
|
1709
1709
|
}
|
|
1710
1710
|
http = tslib.__assign(tslib.__assign({}, http), config.http);
|
|
1711
1711
|
});
|
|
1712
|
-
|
|
1712
|
+
if (options.headers) {
|
|
1713
|
+
options.headers = removeDuplicateHeaders(options.headers, http.preserveHeaderCase);
|
|
1714
|
+
}
|
|
1713
1715
|
var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
|
|
1714
1716
|
var body = { operationName: operationName, variables: variables };
|
|
1715
1717
|
if (http.includeExtensions)
|
|
@@ -1875,6 +1877,7 @@ var createHttpLink = function (linkOptions) {
|
|
|
1875
1877
|
options.method = 'GET';
|
|
1876
1878
|
}
|
|
1877
1879
|
if (hasDirectives(['defer'], operation.query)) {
|
|
1880
|
+
options.headers = options.headers || {};
|
|
1878
1881
|
options.headers.accept = "multipart/mixed; deferSpec=20220824, application/json";
|
|
1879
1882
|
}
|
|
1880
1883
|
if (options.method === 'GET') {
|
|
@@ -6082,6 +6085,11 @@ var QueryManager = (function () {
|
|
|
6082
6085
|
onlyRunForcedResolvers: true,
|
|
6083
6086
|
}).then(function (resolved) { return fromData(resolved.data || void 0); });
|
|
6084
6087
|
}
|
|
6088
|
+
if (errorPolicy === 'none' &&
|
|
6089
|
+
networkStatus === exports.NetworkStatus.refetch &&
|
|
6090
|
+
Array.isArray(diff.missing)) {
|
|
6091
|
+
return fromData(void 0);
|
|
6092
|
+
}
|
|
6085
6093
|
return fromData(data);
|
|
6086
6094
|
};
|
|
6087
6095
|
var cacheWriteBehavior = fetchPolicy === "no-cache" ? 0 :
|
|
@@ -6632,11 +6640,19 @@ var InternalState = (function () {
|
|
|
6632
6640
|
InternalState.prototype.forceUpdate = function () {
|
|
6633
6641
|
__DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
|
|
6634
6642
|
};
|
|
6635
|
-
InternalState.prototype.asyncUpdate = function () {
|
|
6643
|
+
InternalState.prototype.asyncUpdate = function (signal) {
|
|
6636
6644
|
var _this = this;
|
|
6637
|
-
return new Promise(function (resolve) {
|
|
6645
|
+
return new Promise(function (resolve, reject) {
|
|
6646
|
+
var watchQueryOptions = _this.watchQueryOptions;
|
|
6647
|
+
var handleAborted = function () {
|
|
6648
|
+
_this.asyncResolveFns.delete(resolve);
|
|
6649
|
+
_this.optionsToIgnoreOnce.delete(watchQueryOptions);
|
|
6650
|
+
signal.removeEventListener('abort', handleAborted);
|
|
6651
|
+
reject(signal.reason);
|
|
6652
|
+
};
|
|
6638
6653
|
_this.asyncResolveFns.add(resolve);
|
|
6639
|
-
_this.optionsToIgnoreOnce.add(
|
|
6654
|
+
_this.optionsToIgnoreOnce.add(watchQueryOptions);
|
|
6655
|
+
signal.addEventListener('abort', handleAborted);
|
|
6640
6656
|
_this.forceUpdate();
|
|
6641
6657
|
});
|
|
6642
6658
|
};
|
|
@@ -6813,9 +6829,10 @@ var InternalState = (function () {
|
|
|
6813
6829
|
InternalState.prototype.handleErrorOrCompleted = function (result) {
|
|
6814
6830
|
var _this = this;
|
|
6815
6831
|
if (!result.loading) {
|
|
6832
|
+
var error_1 = this.toApolloError(result);
|
|
6816
6833
|
Promise.resolve().then(function () {
|
|
6817
|
-
if (
|
|
6818
|
-
_this.onError(
|
|
6834
|
+
if (error_1) {
|
|
6835
|
+
_this.onError(error_1);
|
|
6819
6836
|
}
|
|
6820
6837
|
else if (result.data) {
|
|
6821
6838
|
_this.onCompleted(result.data);
|
|
@@ -6825,6 +6842,11 @@ var InternalState = (function () {
|
|
|
6825
6842
|
});
|
|
6826
6843
|
}
|
|
6827
6844
|
};
|
|
6845
|
+
InternalState.prototype.toApolloError = function (result) {
|
|
6846
|
+
return isNonEmptyArray(result.errors)
|
|
6847
|
+
? new ApolloError({ graphQLErrors: result.errors })
|
|
6848
|
+
: result.error;
|
|
6849
|
+
};
|
|
6828
6850
|
InternalState.prototype.getCurrentResult = function () {
|
|
6829
6851
|
if (!this.result) {
|
|
6830
6852
|
this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
|
|
@@ -6867,6 +6889,7 @@ var EAGER_METHODS = [
|
|
|
6867
6889
|
'subscribeToMore',
|
|
6868
6890
|
];
|
|
6869
6891
|
function useLazyQuery(query, options) {
|
|
6892
|
+
var abortControllersRef = React.useRef(new Set());
|
|
6870
6893
|
var internalState = useInternalState(useApolloClient(options && options.client), query);
|
|
6871
6894
|
var execOptionsRef = React.useRef();
|
|
6872
6895
|
var merged = execOptionsRef.current
|
|
@@ -6897,14 +6920,28 @@ function useLazyQuery(query, options) {
|
|
|
6897
6920
|
return eagerMethods;
|
|
6898
6921
|
}, []);
|
|
6899
6922
|
Object.assign(result, eagerMethods);
|
|
6923
|
+
React.useEffect(function () {
|
|
6924
|
+
return function () {
|
|
6925
|
+
abortControllersRef.current.forEach(function (controller) {
|
|
6926
|
+
controller.abort();
|
|
6927
|
+
});
|
|
6928
|
+
};
|
|
6929
|
+
}, []);
|
|
6900
6930
|
var execute = React.useCallback(function (executeOptions) {
|
|
6931
|
+
var controller = new AbortController();
|
|
6932
|
+
abortControllersRef.current.add(controller);
|
|
6901
6933
|
execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
|
|
6902
6934
|
fetchPolicy: initialFetchPolicy,
|
|
6903
6935
|
};
|
|
6904
6936
|
var promise = internalState
|
|
6905
|
-
.asyncUpdate()
|
|
6906
|
-
.then(function (queryResult) {
|
|
6907
|
-
|
|
6937
|
+
.asyncUpdate(controller.signal)
|
|
6938
|
+
.then(function (queryResult) {
|
|
6939
|
+
abortControllersRef.current.delete(controller);
|
|
6940
|
+
return Object.assign(queryResult, eagerMethods);
|
|
6941
|
+
});
|
|
6942
|
+
promise.catch(function () {
|
|
6943
|
+
abortControllersRef.current.delete(controller);
|
|
6944
|
+
});
|
|
6908
6945
|
return promise;
|
|
6909
6946
|
}, []);
|
|
6910
6947
|
return [execute, result];
|
|
@@ -6945,7 +6982,7 @@ function useMutation(mutation, options) {
|
|
|
6945
6982
|
var mutationId = ++ref.current.mutationId;
|
|
6946
6983
|
var clientOptions = mergeOptions(baseOptions, executeOptions);
|
|
6947
6984
|
return client.mutate(clientOptions).then(function (response) {
|
|
6948
|
-
var _a
|
|
6985
|
+
var _a;
|
|
6949
6986
|
var data = response.data, errors = response.errors;
|
|
6950
6987
|
var error = errors && errors.length > 0
|
|
6951
6988
|
? new ApolloError({ graphQLErrors: errors })
|
|
@@ -6963,11 +7000,11 @@ function useMutation(mutation, options) {
|
|
|
6963
7000
|
setResult(ref.current.result = result_1);
|
|
6964
7001
|
}
|
|
6965
7002
|
}
|
|
6966
|
-
|
|
6967
|
-
|
|
7003
|
+
var onCompleted = executeOptions.onCompleted || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted);
|
|
7004
|
+
onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response.data, clientOptions);
|
|
6968
7005
|
return response;
|
|
6969
7006
|
}).catch(function (error) {
|
|
6970
|
-
var _a
|
|
7007
|
+
var _a;
|
|
6971
7008
|
if (mutationId === ref.current.mutationId &&
|
|
6972
7009
|
ref.current.isMounted) {
|
|
6973
7010
|
var result_2 = {
|
|
@@ -6981,9 +7018,9 @@ function useMutation(mutation, options) {
|
|
|
6981
7018
|
setResult(ref.current.result = result_2);
|
|
6982
7019
|
}
|
|
6983
7020
|
}
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
7021
|
+
var onError = executeOptions.onError || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError);
|
|
7022
|
+
if (onError) {
|
|
7023
|
+
onError(error, clientOptions);
|
|
6987
7024
|
return { data: void 0, errors: error };
|
|
6988
7025
|
}
|
|
6989
7026
|
throw error;
|
|
@@ -7160,20 +7197,21 @@ function useFragment_experimental(options) {
|
|
|
7160
7197
|
var diffOptions = tslib.__assign(tslib.__assign({}, rest), { id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
|
|
7161
7198
|
var resultRef = React.useRef();
|
|
7162
7199
|
var latestDiff = cache.diff(diffOptions);
|
|
7200
|
+
var getSnapshot = function () {
|
|
7201
|
+
var latestDiffToResult = diffToResult(latestDiff);
|
|
7202
|
+
return resultRef.current &&
|
|
7203
|
+
equality.equal(resultRef.current.data, latestDiffToResult.data)
|
|
7204
|
+
? resultRef.current
|
|
7205
|
+
: (resultRef.current = latestDiffToResult);
|
|
7206
|
+
};
|
|
7163
7207
|
return useSyncExternalStore(function (forceUpdate) {
|
|
7164
7208
|
return cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
|
|
7165
7209
|
if (!equality.equal(diff, latestDiff)) {
|
|
7166
|
-
resultRef.current = diffToResult(latestDiff = diff);
|
|
7210
|
+
resultRef.current = diffToResult((latestDiff = diff));
|
|
7167
7211
|
forceUpdate();
|
|
7168
7212
|
}
|
|
7169
7213
|
} }));
|
|
7170
|
-
},
|
|
7171
|
-
var latestDiffToResult = diffToResult(latestDiff);
|
|
7172
|
-
return resultRef.current &&
|
|
7173
|
-
equality.equal(resultRef.current.data, latestDiffToResult.data)
|
|
7174
|
-
? resultRef.current
|
|
7175
|
-
: (resultRef.current = latestDiffToResult);
|
|
7176
|
-
});
|
|
7214
|
+
}, getSnapshot, getSnapshot);
|
|
7177
7215
|
}
|
|
7178
7216
|
function diffToResult(diff) {
|
|
7179
7217
|
var result = {
|