@apollo/client 3.8.0-alpha.1 → 3.8.0-alpha.10
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 +3 -1
- package/apollo-client.cjs +471 -291
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +54 -44
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +54 -44
- package/cache/core/cache.d.ts +1 -1
- package/cache/core/cache.d.ts.map +1 -1
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +3 -2
- package/cache/core/types/DataProxy.d.ts.map +1 -1
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/core/types/common.d.ts +7 -7
- package/cache/core/types/common.d.ts.map +1 -1
- package/cache/inmemory/entityStore.d.ts +1 -1
- package/cache/inmemory/entityStore.d.ts.map +1 -1
- package/cache/inmemory/entityStore.js +1 -1
- package/cache/inmemory/helpers.d.ts +2 -2
- package/cache/inmemory/helpers.d.ts.map +1 -1
- package/cache/inmemory/helpers.js +2 -2
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +3 -2
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +1 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/object-canon.d.ts +0 -1
- package/cache/inmemory/object-canon.d.ts.map +1 -1
- package/cache/inmemory/object-canon.js +1 -1
- package/cache/inmemory/object-canon.js.map +1 -1
- package/cache/inmemory/policies.d.ts +12 -12
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +15 -4
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/reactiveVars.d.ts +1 -1
- package/cache/inmemory/reactiveVars.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +2 -2
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +1 -1
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +4 -4
- package/cache/inmemory/types.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +1 -1
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +1 -1
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +10 -9
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +11 -5
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.d.ts +12 -7
- package/core/LocalState.d.ts.map +1 -1
- package/core/LocalState.js +71 -17
- package/core/LocalState.js.map +1 -1
- package/core/ObservableQuery.d.ts +5 -5
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +2 -2
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +1 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +1 -1
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +7 -7
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +22 -12
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +132 -69
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +132 -69
- package/core/index.js +2 -2
- package/core/index.js.map +1 -1
- package/core/types.d.ts +21 -17
- 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 +11 -11
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/errors/index.d.ts +2 -2
- package/errors/index.d.ts.map +1 -1
- package/invariantErrorCodes.js +36 -35
- package/link/batch/batch.cjs +5 -3
- package/link/batch/batch.cjs.map +1 -1
- package/link/batch/batch.cjs.native.js +5 -3
- package/link/batch/batching.d.ts +2 -2
- package/link/batch/batching.d.ts.map +1 -1
- package/link/batch/batching.js +5 -3
- package/link/batch/batching.js.map +1 -1
- package/link/batch-http/batch-http.cjs +12 -2
- package/link/batch-http/batch-http.cjs.map +1 -1
- package/link/batch-http/batch-http.cjs.native.js +12 -2
- package/link/batch-http/batchHttpLink.d.ts.map +1 -1
- package/link/batch-http/batchHttpLink.js +13 -3
- package/link/batch-http/batchHttpLink.js.map +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/ApolloLink.js +2 -2
- package/link/core/core.cjs +2 -2
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +2 -2
- package/link/core/types.d.ts +15 -15
- package/link/core/types.d.ts.map +1 -1
- package/link/core/types.js.map +1 -1
- package/link/http/checkFetcher.js +2 -2
- package/link/http/createHttpLink.d.ts +0 -1
- package/link/http/createHttpLink.d.ts.map +1 -1
- package/link/http/createHttpLink.js +10 -2
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/http.cjs +20 -38
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +20 -38
- package/link/http/iterators/async.js.map +1 -1
- package/link/http/iterators/nodeStream.js.map +1 -1
- package/link/http/iterators/promise.js.map +1 -1
- package/link/http/iterators/reader.js.map +1 -1
- package/link/http/parseAndCheckHttpResponse.d.ts +2 -2
- package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/responseIterator.js +1 -1
- package/link/http/responseIterator.js.map +1 -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/link/http/serializeFetchParameter.d.ts +1 -1
- package/link/http/serializeFetchParameter.d.ts.map +1 -1
- package/link/http/serializeFetchParameter.js +2 -2
- package/link/persisted-queries/index.d.ts +2 -2
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +3 -3
- package/link/persisted-queries/persisted-queries.cjs +3 -3
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +3 -3
- package/link/utils/throwServerError.d.ts +1 -1
- package/link/utils/throwServerError.d.ts.map +1 -1
- package/link/utils/toPromise.js +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js +2 -2
- package/package.json +25 -23
- package/react/cache/SuspenseCache.d.ts +1 -1
- package/react/cache/SuspenseCache.d.ts.map +1 -1
- package/react/cache/SuspenseCache.js.map +1 -1
- package/react/components/Query.d.ts +2 -2
- package/react/components/Query.d.ts.map +1 -1
- package/react/components/Query.js.map +1 -1
- package/react/components/Subscription.d.ts +2 -2
- package/react/components/Subscription.d.ts.map +1 -1
- package/react/components/Subscription.js.map +1 -1
- package/react/components/types.d.ts +2 -2
- package/react/components/types.d.ts.map +1 -1
- package/react/components/types.js.map +1 -1
- package/react/context/ApolloConsumer.js +2 -2
- package/react/context/ApolloProvider.js +2 -2
- package/react/context/context.cjs +4 -4
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +4 -4
- package/react/hoc/graphql.d.ts +2 -1
- package/react/hoc/graphql.d.ts.map +1 -1
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc-utils.d.ts +1 -1
- package/react/hoc/hoc-utils.d.ts.map +1 -1
- package/react/hoc/hoc-utils.js +2 -2
- package/react/hoc/hoc.cjs +4 -4
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +4 -4
- package/react/hoc/mutation-hoc.d.ts +2 -2
- package/react/hoc/mutation-hoc.d.ts.map +1 -1
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.d.ts +1 -1
- package/react/hoc/query-hoc.d.ts.map +1 -1
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.d.ts +1 -1
- package/react/hoc/subscription-hoc.d.ts.map +1 -1
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/types.d.ts +6 -6
- package/react/hoc/types.d.ts.map +1 -1
- package/react/hoc/types.js.map +1 -1
- package/react/hoc/withApollo.js +2 -2
- package/react/hooks/hooks.cjs +129 -69
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +129 -69
- package/react/hooks/internal/index.d.ts +1 -0
- package/react/hooks/internal/index.d.ts.map +1 -1
- package/react/hooks/internal/index.js +1 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts +3 -0
- package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +1 -0
- package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -0
- package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -0
- package/react/hooks/useApolloClient.js +2 -2
- package/react/hooks/useFragment.d.ts +4 -2
- 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 +2 -2
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +22 -8
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +2 -2
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +9 -8
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +6 -5
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +21 -7
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +2 -3
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +1 -2
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseCache.d.ts +2 -1
- package/react/hooks/useSuspenseCache.d.ts.map +1 -1
- package/react/hooks/useSuspenseCache.js +7 -5
- package/react/hooks/useSuspenseCache.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +11 -4
- package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
- package/react/hooks/useSuspenseQuery.js +54 -30
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.d.ts +1 -1
- package/react/hooks/useSyncExternalStore.d.ts.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/hooks/useSyncExternalStore.js.map +1 -1
- package/react/parser/index.js +6 -6
- package/react/parser/parser.cjs +10 -10
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +10 -10
- package/react/ssr/RenderPromises.d.ts +4 -4
- package/react/ssr/RenderPromises.d.ts.map +1 -1
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/getDataFromTree.d.ts +1 -1
- package/react/ssr/getDataFromTree.d.ts.map +1 -1
- package/react/types/types.d.ts +26 -23
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +30 -3
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +30 -3
- package/testing/core/index.d.ts +2 -1
- 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/itAsync.js.map +1 -1
- package/testing/core/mocking/mockFetch.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +8 -4
- package/testing/core/mocking/mockLink.d.ts.map +1 -1
- package/testing/core/mocking/mockLink.js +14 -4
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts.map +1 -1
- package/testing/core/mocking/mockQueryManager.js +3 -3
- package/testing/core/mocking/mockQueryManager.js.map +1 -1
- package/testing/core/mocking/mockWatchQuery.d.ts +1 -1
- package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -1
- package/testing/core/mocking/mockWatchQuery.js +4 -5
- package/testing/core/mocking/mockWatchQuery.js.map +1 -1
- package/testing/core/observableToPromise.d.ts +2 -2
- package/testing/core/observableToPromise.d.ts.map +1 -1
- package/testing/core/observableToPromise.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/testing/react/MockedProvider.d.ts +1 -0
- package/testing/react/MockedProvider.d.ts.map +1 -1
- package/testing/react/MockedProvider.js +2 -2
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +2 -2
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +2 -2
- package/utilities/common/arrays.d.ts +1 -0
- package/utilities/common/arrays.d.ts.map +1 -1
- package/utilities/common/arrays.js +1 -0
- package/utilities/common/arrays.js.map +1 -1
- package/utilities/common/cloneDeep.js.map +1 -1
- package/utilities/common/errorHandling.d.ts +2 -2
- package/utilities/common/errorHandling.d.ts.map +1 -1
- package/utilities/common/errorHandling.js.map +1 -1
- package/utilities/common/incrementalResult.d.ts +4 -4
- package/utilities/common/incrementalResult.d.ts.map +1 -1
- package/utilities/common/incrementalResult.js.map +1 -1
- package/utilities/common/maybeDeepFreeze.d.ts +0 -1
- package/utilities/common/maybeDeepFreeze.d.ts.map +1 -1
- package/utilities/common/maybeDeepFreeze.js +1 -1
- package/utilities/common/maybeDeepFreeze.js.map +1 -1
- package/utilities/common/mergeDeep.d.ts +2 -2
- package/utilities/common/mergeDeep.d.ts.map +1 -1
- package/utilities/common/mergeOptions.d.ts +3 -3
- package/utilities/common/mergeOptions.d.ts.map +1 -1
- package/utilities/common/mergeOptions.js.map +1 -1
- package/utilities/globals/DEV.d.ts +1 -1
- package/utilities/globals/DEV.d.ts.map +1 -1
- package/utilities/globals/DEV.js +1 -17
- package/utilities/globals/DEV.js.map +1 -1
- package/utilities/globals/global.d.ts +5 -2
- package/utilities/globals/global.d.ts.map +1 -1
- package/utilities/globals/global.js.map +1 -1
- package/utilities/globals/globals.cjs +5 -22
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +5 -22
- package/utilities/globals/index.d.ts +1 -1
- package/utilities/globals/index.d.ts.map +1 -1
- package/utilities/globals/index.js +1 -4
- package/utilities/globals/index.js.map +1 -1
- package/utilities/graphql/directives.d.ts +2 -2
- package/utilities/graphql/directives.d.ts.map +1 -1
- package/utilities/graphql/directives.js +1 -1
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.d.ts +1 -1
- package/utilities/graphql/fragments.d.ts.map +1 -1
- package/utilities/graphql/fragments.js +1 -1
- package/utilities/graphql/getFromAST.d.ts.map +1 -1
- package/utilities/graphql/getFromAST.js +8 -4
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/graphql/storeUtils.d.ts +3 -3
- package/utilities/graphql/storeUtils.d.ts.map +1 -1
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.d.ts +9 -9
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js +168 -91
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +2 -0
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +2 -0
- package/utilities/index.js.map +1 -1
- package/utilities/observables/Concast.d.ts +5 -5
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js +2 -2
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/observables/asyncMap.js.map +1 -1
- package/utilities/policies/pagination.d.ts +7 -7
- package/utilities/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/types/IsStrictlyAny.d.ts +3 -3
- package/utilities/types/IsStrictlyAny.d.ts.map +1 -1
- package/utilities/utilities.cjs +252 -124
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +252 -124
- package/version.js +1 -1
package/react/hooks/hooks.cjs
CHANGED
|
@@ -29,9 +29,9 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
29
29
|
function useApolloClient(override) {
|
|
30
30
|
var context$1 = React.useContext(context.getApolloContext());
|
|
31
31
|
var client = override || context$1.client;
|
|
32
|
-
__DEV__ ? globals.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
|
|
32
|
+
globals.__DEV__ ? globals.invariant(!!client, 'Could not find "client" in the context or passed in as an option. ' +
|
|
33
33
|
'Wrap the root component in an <ApolloProvider>, or pass an ApolloClient ' +
|
|
34
|
-
'instance in via options.') : globals.invariant(!!client,
|
|
34
|
+
'instance in via options.') : globals.invariant(!!client, 32);
|
|
35
35
|
return client;
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -40,11 +40,11 @@ var uSESKey = "useSyncExternalStore";
|
|
|
40
40
|
var realHook = React__namespace[uSESKey];
|
|
41
41
|
var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
|
|
42
42
|
var value = getSnapshot();
|
|
43
|
-
if (__DEV__ &&
|
|
43
|
+
if (globals.__DEV__ &&
|
|
44
44
|
!didWarnUncachedGetSnapshot &&
|
|
45
45
|
value !== getSnapshot()) {
|
|
46
46
|
didWarnUncachedGetSnapshot = true;
|
|
47
|
-
__DEV__ && globals.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
47
|
+
globals.__DEV__ && globals.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
48
48
|
}
|
|
49
49
|
var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
|
|
50
50
|
if (utilities.canUseLayoutEffect) {
|
|
@@ -126,13 +126,21 @@ var InternalState = (function () {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
InternalState.prototype.forceUpdate = function () {
|
|
129
|
-
__DEV__ && globals.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
|
|
129
|
+
globals.__DEV__ && globals.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
|
|
130
130
|
};
|
|
131
|
-
InternalState.prototype.asyncUpdate = function () {
|
|
131
|
+
InternalState.prototype.asyncUpdate = function (signal) {
|
|
132
132
|
var _this = this;
|
|
133
|
-
return new Promise(function (resolve) {
|
|
133
|
+
return new Promise(function (resolve, reject) {
|
|
134
|
+
var watchQueryOptions = _this.watchQueryOptions;
|
|
135
|
+
var handleAborted = function () {
|
|
136
|
+
_this.asyncResolveFns.delete(resolve);
|
|
137
|
+
_this.optionsToIgnoreOnce.delete(watchQueryOptions);
|
|
138
|
+
signal.removeEventListener('abort', handleAborted);
|
|
139
|
+
reject(signal.reason);
|
|
140
|
+
};
|
|
134
141
|
_this.asyncResolveFns.add(resolve);
|
|
135
|
-
_this.optionsToIgnoreOnce.add(
|
|
142
|
+
_this.optionsToIgnoreOnce.add(watchQueryOptions);
|
|
143
|
+
signal.addEventListener('abort', handleAborted);
|
|
136
144
|
_this.forceUpdate();
|
|
137
145
|
});
|
|
138
146
|
};
|
|
@@ -182,7 +190,7 @@ var InternalState = (function () {
|
|
|
182
190
|
}
|
|
183
191
|
};
|
|
184
192
|
var subscription = obsQuery.subscribe(onNext, onError);
|
|
185
|
-
return function () { return subscription.unsubscribe(); };
|
|
193
|
+
return function () { return setTimeout(function () { return subscription.unsubscribe(); }); };
|
|
186
194
|
}, [
|
|
187
195
|
obsQuery,
|
|
188
196
|
this.renderPromises,
|
|
@@ -309,9 +317,10 @@ var InternalState = (function () {
|
|
|
309
317
|
InternalState.prototype.handleErrorOrCompleted = function (result, previousResult) {
|
|
310
318
|
var _this = this;
|
|
311
319
|
if (!result.loading) {
|
|
320
|
+
var error_1 = this.toApolloError(result);
|
|
312
321
|
Promise.resolve().then(function () {
|
|
313
|
-
if (
|
|
314
|
-
_this.onError(
|
|
322
|
+
if (error_1) {
|
|
323
|
+
_this.onError(error_1);
|
|
315
324
|
}
|
|
316
325
|
else if (result.data &&
|
|
317
326
|
(previousResult === null || previousResult === void 0 ? void 0 : previousResult.networkStatus) !== result.networkStatus &&
|
|
@@ -319,10 +328,15 @@ var InternalState = (function () {
|
|
|
319
328
|
_this.onCompleted(result.data);
|
|
320
329
|
}
|
|
321
330
|
}).catch(function (error) {
|
|
322
|
-
__DEV__ && globals.invariant.warn(error);
|
|
331
|
+
globals.__DEV__ && globals.invariant.warn(error);
|
|
323
332
|
});
|
|
324
333
|
}
|
|
325
334
|
};
|
|
335
|
+
InternalState.prototype.toApolloError = function (result) {
|
|
336
|
+
return utilities.isNonEmptyArray(result.errors)
|
|
337
|
+
? new errors.ApolloError({ graphQLErrors: result.errors })
|
|
338
|
+
: result.error;
|
|
339
|
+
};
|
|
326
340
|
InternalState.prototype.getCurrentResult = function () {
|
|
327
341
|
if (!this.result) {
|
|
328
342
|
this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
|
|
@@ -365,11 +379,11 @@ var EAGER_METHODS = [
|
|
|
365
379
|
'subscribeToMore',
|
|
366
380
|
];
|
|
367
381
|
function useLazyQuery(query, options) {
|
|
368
|
-
var
|
|
382
|
+
var _a, _b;
|
|
383
|
+
var abortControllersRef = React.useRef(new Set());
|
|
369
384
|
var execOptionsRef = React.useRef();
|
|
370
|
-
var merged = execOptionsRef.current
|
|
371
|
-
|
|
372
|
-
: options;
|
|
385
|
+
var merged = execOptionsRef.current ? utilities.mergeOptions(options, execOptionsRef.current) : options;
|
|
386
|
+
var internalState = useInternalState(useApolloClient(options && options.client), (_b = (_a = execOptionsRef.current) === null || _a === void 0 ? void 0 : _a.query) !== null && _b !== void 0 ? _b : query);
|
|
373
387
|
var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
|
|
374
388
|
var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
|
|
375
389
|
internalState.getDefaultFetchPolicy();
|
|
@@ -395,14 +409,28 @@ function useLazyQuery(query, options) {
|
|
|
395
409
|
return eagerMethods;
|
|
396
410
|
}, []);
|
|
397
411
|
Object.assign(result, eagerMethods);
|
|
412
|
+
React.useEffect(function () {
|
|
413
|
+
return function () {
|
|
414
|
+
abortControllersRef.current.forEach(function (controller) {
|
|
415
|
+
controller.abort();
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
}, []);
|
|
398
419
|
var execute = React.useCallback(function (executeOptions) {
|
|
420
|
+
var controller = new AbortController();
|
|
421
|
+
abortControllersRef.current.add(controller);
|
|
399
422
|
execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
|
|
400
423
|
fetchPolicy: initialFetchPolicy,
|
|
401
424
|
};
|
|
402
425
|
var promise = internalState
|
|
403
|
-
.asyncUpdate()
|
|
404
|
-
.then(function (queryResult) {
|
|
405
|
-
|
|
426
|
+
.asyncUpdate(controller.signal)
|
|
427
|
+
.then(function (queryResult) {
|
|
428
|
+
abortControllersRef.current.delete(controller);
|
|
429
|
+
return Object.assign(queryResult, eagerMethods);
|
|
430
|
+
});
|
|
431
|
+
promise.catch(function () {
|
|
432
|
+
abortControllersRef.current.delete(controller);
|
|
433
|
+
});
|
|
406
434
|
return promise;
|
|
407
435
|
}, []);
|
|
408
436
|
return [execute, result];
|
|
@@ -429,8 +457,9 @@ function useMutation(mutation, options) {
|
|
|
429
457
|
}
|
|
430
458
|
var execute = React.useCallback(function (executeOptions) {
|
|
431
459
|
if (executeOptions === void 0) { executeOptions = {}; }
|
|
432
|
-
var _a = ref.current,
|
|
460
|
+
var _a = ref.current, options = _a.options, mutation = _a.mutation;
|
|
433
461
|
var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
|
|
462
|
+
var client = executeOptions.client || ref.current.client;
|
|
434
463
|
if (!ref.current.result.loading && !baseOptions.ignoreResults && ref.current.isMounted) {
|
|
435
464
|
setResult(ref.current.result = {
|
|
436
465
|
loading: true,
|
|
@@ -443,7 +472,7 @@ function useMutation(mutation, options) {
|
|
|
443
472
|
var mutationId = ++ref.current.mutationId;
|
|
444
473
|
var clientOptions = core.mergeOptions(baseOptions, executeOptions);
|
|
445
474
|
return client.mutate(clientOptions).then(function (response) {
|
|
446
|
-
var _a
|
|
475
|
+
var _a;
|
|
447
476
|
var data = response.data, errors$1 = response.errors;
|
|
448
477
|
var error = errors$1 && errors$1.length > 0
|
|
449
478
|
? new errors.ApolloError({ graphQLErrors: errors$1 })
|
|
@@ -461,11 +490,11 @@ function useMutation(mutation, options) {
|
|
|
461
490
|
setResult(ref.current.result = result_1);
|
|
462
491
|
}
|
|
463
492
|
}
|
|
464
|
-
|
|
465
|
-
|
|
493
|
+
var onCompleted = executeOptions.onCompleted || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted);
|
|
494
|
+
onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response.data, clientOptions);
|
|
466
495
|
return response;
|
|
467
496
|
}).catch(function (error) {
|
|
468
|
-
var _a
|
|
497
|
+
var _a;
|
|
469
498
|
if (mutationId === ref.current.mutationId &&
|
|
470
499
|
ref.current.isMounted) {
|
|
471
500
|
var result_2 = {
|
|
@@ -479,9 +508,9 @@ function useMutation(mutation, options) {
|
|
|
479
508
|
setResult(ref.current.result = result_2);
|
|
480
509
|
}
|
|
481
510
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
511
|
+
var onError = executeOptions.onError || ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError);
|
|
512
|
+
if (onError) {
|
|
513
|
+
onError(error, clientOptions);
|
|
485
514
|
return { data: void 0, errors: error };
|
|
486
515
|
}
|
|
487
516
|
throw error;
|
|
@@ -514,12 +543,12 @@ function useSubscription(subscription, options) {
|
|
|
514
543
|
if (!hasIssuedDeprecationWarningRef.current) {
|
|
515
544
|
hasIssuedDeprecationWarningRef.current = true;
|
|
516
545
|
if (options === null || options === void 0 ? void 0 : options.onSubscriptionData) {
|
|
517
|
-
__DEV__ && globals.invariant.warn(options.onData
|
|
546
|
+
globals.__DEV__ && globals.invariant.warn(options.onData
|
|
518
547
|
? "'useSubscription' supports only the 'onSubscriptionData' or 'onData' option, but not both. Only the 'onData' option will be used."
|
|
519
548
|
: "'onSubscriptionData' is deprecated and will be removed in a future major version. Please use the 'onData' option instead.");
|
|
520
549
|
}
|
|
521
550
|
if (options === null || options === void 0 ? void 0 : options.onSubscriptionComplete) {
|
|
522
|
-
__DEV__ && globals.invariant.warn(options.onComplete
|
|
551
|
+
globals.__DEV__ && globals.invariant.warn(options.onComplete
|
|
523
552
|
? "'useSubscription' supports only the 'onSubscriptionComplete' or 'onComplete' option, but not both. Only the 'onComplete' option will be used."
|
|
524
553
|
: "'onSubscriptionComplete' is deprecated and will be removed in a future major version. Please use the 'onComplete' option instead.");
|
|
525
554
|
}
|
|
@@ -658,20 +687,21 @@ function useFragment_experimental(options) {
|
|
|
658
687
|
var diffOptions = tslib.__assign(tslib.__assign({}, rest), { id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
|
|
659
688
|
var resultRef = React.useRef();
|
|
660
689
|
var latestDiff = cache.diff(diffOptions);
|
|
690
|
+
var getSnapshot = function () {
|
|
691
|
+
var latestDiffToResult = diffToResult(latestDiff);
|
|
692
|
+
return resultRef.current &&
|
|
693
|
+
equality.equal(resultRef.current.data, latestDiffToResult.data)
|
|
694
|
+
? resultRef.current
|
|
695
|
+
: (resultRef.current = latestDiffToResult);
|
|
696
|
+
};
|
|
661
697
|
return useSyncExternalStore(function (forceUpdate) {
|
|
662
698
|
return cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
|
|
663
699
|
if (!equality.equal(diff, latestDiff)) {
|
|
664
|
-
resultRef.current = diffToResult(latestDiff = diff);
|
|
700
|
+
resultRef.current = diffToResult((latestDiff = diff));
|
|
665
701
|
forceUpdate();
|
|
666
702
|
}
|
|
667
703
|
} }));
|
|
668
|
-
},
|
|
669
|
-
var latestDiffToResult = diffToResult(latestDiff);
|
|
670
|
-
return resultRef.current &&
|
|
671
|
-
equality.equal(resultRef.current.data, latestDiffToResult.data)
|
|
672
|
-
? resultRef.current
|
|
673
|
-
: (resultRef.current = latestDiffToResult);
|
|
674
|
-
});
|
|
704
|
+
}, getSnapshot, getSnapshot);
|
|
675
705
|
}
|
|
676
706
|
function diffToResult(diff) {
|
|
677
707
|
var result = {
|
|
@@ -692,10 +722,16 @@ function useDeepMemo(memoFn, deps) {
|
|
|
692
722
|
return ref.current.value;
|
|
693
723
|
}
|
|
694
724
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
725
|
+
var useIsomorphicLayoutEffect = utilities.canUseLayoutEffect
|
|
726
|
+
? React.useLayoutEffect
|
|
727
|
+
: React.useEffect;
|
|
728
|
+
|
|
729
|
+
function useSuspenseCache(override) {
|
|
730
|
+
var context$1 = React.useContext(context.getApolloContext());
|
|
731
|
+
var suspenseCache = override || context$1.suspenseCache;
|
|
732
|
+
globals.__DEV__ ? globals.invariant(suspenseCache, 'Could not find a "suspenseCache" in the context or passed in as an option. ' +
|
|
733
|
+
'Wrap the root component in an <ApolloProvider> and provide a suspenseCache, ' +
|
|
734
|
+
'or pass a SuspenseCache instance in via options.') : globals.invariant(suspenseCache, 33);
|
|
699
735
|
return suspenseCache;
|
|
700
736
|
}
|
|
701
737
|
|
|
@@ -710,7 +746,7 @@ var DEFAULT_SUSPENSE_POLICY = 'always';
|
|
|
710
746
|
var DEFAULT_ERROR_POLICY = 'none';
|
|
711
747
|
function useSuspenseQuery_experimental(query, options) {
|
|
712
748
|
if (options === void 0) { options = Object.create(null); }
|
|
713
|
-
var suspenseCache = useSuspenseCache();
|
|
749
|
+
var suspenseCache = useSuspenseCache(options.suspenseCache);
|
|
714
750
|
var client = useApolloClient(options.client);
|
|
715
751
|
var watchQueryOptions = useWatchQueryOptions({ query: query, options: options, client: client });
|
|
716
752
|
var previousWatchQueryOptionsRef = React.useRef(watchQueryOptions);
|
|
@@ -724,9 +760,9 @@ function useSuspenseQuery_experimental(query, options) {
|
|
|
724
760
|
var hasFullResult = result.data && !result.partial;
|
|
725
761
|
var hasPartialResult = result.data && result.partial;
|
|
726
762
|
var usePartialResult = returnPartialData && hasPartialResult;
|
|
763
|
+
var allowsThrownErrors = errorPolicy === 'none' && (!deferred || !hasPartialResult);
|
|
727
764
|
if (result.error &&
|
|
728
|
-
|
|
729
|
-
(!deferred || !hasPartialResult)) {
|
|
765
|
+
(result.error.networkError || allowsThrownErrors)) {
|
|
730
766
|
throw result.error;
|
|
731
767
|
}
|
|
732
768
|
if (result.loading) {
|
|
@@ -759,28 +795,42 @@ function useSuspenseQuery_experimental(query, options) {
|
|
|
759
795
|
suspenseCache.remove(query, variables);
|
|
760
796
|
};
|
|
761
797
|
}, []);
|
|
798
|
+
var fetchMore = React.useCallback(function (options) {
|
|
799
|
+
var promise = observable.fetchMore(options);
|
|
800
|
+
suspenseCache.add(query, watchQueryOptions.variables, {
|
|
801
|
+
promise: promise,
|
|
802
|
+
observable: observable,
|
|
803
|
+
});
|
|
804
|
+
return promise;
|
|
805
|
+
}, [observable]);
|
|
806
|
+
var refetch = React.useCallback(function (variables) {
|
|
807
|
+
var promise = observable.refetch(variables);
|
|
808
|
+
suspenseCache.add(query, watchQueryOptions.variables, {
|
|
809
|
+
promise: promise,
|
|
810
|
+
observable: observable,
|
|
811
|
+
});
|
|
812
|
+
return promise;
|
|
813
|
+
}, [observable]);
|
|
814
|
+
var subscribeToMore = React.useCallback(function (options) { return observable.subscribeToMore(options); }, [observable]);
|
|
762
815
|
return React.useMemo(function () {
|
|
763
816
|
return {
|
|
817
|
+
client: client,
|
|
764
818
|
data: result.data,
|
|
765
819
|
error: errorPolicy === 'ignore' ? void 0 : toApolloError(result),
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
observable: observable,
|
|
771
|
-
});
|
|
772
|
-
return promise;
|
|
773
|
-
},
|
|
774
|
-
refetch: function (variables) {
|
|
775
|
-
var promise = observable.refetch(variables);
|
|
776
|
-
suspenseCache.add(query, watchQueryOptions.variables, {
|
|
777
|
-
promise: promise,
|
|
778
|
-
observable: observable,
|
|
779
|
-
});
|
|
780
|
-
return promise;
|
|
781
|
-
},
|
|
820
|
+
networkStatus: result.networkStatus,
|
|
821
|
+
fetchMore: fetchMore,
|
|
822
|
+
refetch: refetch,
|
|
823
|
+
subscribeToMore: subscribeToMore,
|
|
782
824
|
};
|
|
783
|
-
}, [
|
|
825
|
+
}, [
|
|
826
|
+
client,
|
|
827
|
+
fetchMore,
|
|
828
|
+
refetch,
|
|
829
|
+
result,
|
|
830
|
+
observable,
|
|
831
|
+
errorPolicy,
|
|
832
|
+
subscribeToMore,
|
|
833
|
+
]);
|
|
784
834
|
}
|
|
785
835
|
function validateOptions(options) {
|
|
786
836
|
var query = options.query, _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? DEFAULT_FETCH_POLICY : _a, returnPartialData = options.returnPartialData;
|
|
@@ -789,11 +839,11 @@ function validateOptions(options) {
|
|
|
789
839
|
validatePartialDataReturn(fetchPolicy, returnPartialData);
|
|
790
840
|
}
|
|
791
841
|
function validateFetchPolicy(fetchPolicy) {
|
|
792
|
-
__DEV__ ? globals.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : globals.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy),
|
|
842
|
+
globals.__DEV__ ? globals.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), "The fetch policy `".concat(fetchPolicy, "` is not supported with suspense.")) : globals.invariant(SUPPORTED_FETCH_POLICIES.includes(fetchPolicy), 34);
|
|
793
843
|
}
|
|
794
844
|
function validatePartialDataReturn(fetchPolicy, returnPartialData) {
|
|
795
845
|
if (fetchPolicy === 'no-cache' && returnPartialData) {
|
|
796
|
-
__DEV__ && globals.invariant.warn('Using `returnPartialData` with a `no-cache` fetch policy has no effect. To read partial data from the cache, consider using an alternate fetch policy.');
|
|
846
|
+
globals.__DEV__ && globals.invariant.warn('Using `returnPartialData` with a `no-cache` fetch policy has no effect. To read partial data from the cache, consider using an alternate fetch policy.');
|
|
797
847
|
}
|
|
798
848
|
}
|
|
799
849
|
function toApolloError(result) {
|
|
@@ -823,7 +873,7 @@ function useWatchQueryOptions(_a) {
|
|
|
823
873
|
var errorPolicy = options.errorPolicy, fetchPolicy = options.fetchPolicy, _a = options.suspensePolicy, suspensePolicy = _a === void 0 ? DEFAULT_SUSPENSE_POLICY : _a, variables = options.variables, watchQueryOptions = tslib.__rest(options, ["errorPolicy", "fetchPolicy", "suspensePolicy", "variables"]);
|
|
824
874
|
return tslib.__assign(tslib.__assign({}, watchQueryOptions), { query: query, errorPolicy: errorPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.errorPolicy) || DEFAULT_ERROR_POLICY, fetchPolicy: fetchPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.fetchPolicy) || DEFAULT_FETCH_POLICY, notifyOnNetworkStatusChange: suspensePolicy === 'always', fetchOnFirstSubscribe: false, variables: utilities.compact(tslib.__assign(tslib.__assign({}, defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.variables), variables)) });
|
|
825
875
|
}, [options, query, defaultOptions]);
|
|
826
|
-
if (__DEV__) {
|
|
876
|
+
if (globals.__DEV__) {
|
|
827
877
|
validateOptions(watchQueryOptions);
|
|
828
878
|
}
|
|
829
879
|
return watchQueryOptions;
|
|
@@ -834,16 +884,18 @@ function useIsDeferred(query) {
|
|
|
834
884
|
function useObservableQueryResult(observable) {
|
|
835
885
|
var resultRef = React.useRef();
|
|
836
886
|
var isMountedRef = React.useRef(false);
|
|
887
|
+
var subscribeTimeoutRef = React.useRef();
|
|
837
888
|
if (!resultRef.current) {
|
|
838
889
|
resultRef.current = observable.getCurrentResult();
|
|
839
890
|
}
|
|
840
|
-
|
|
891
|
+
useIsomorphicLayoutEffect(function () {
|
|
841
892
|
isMountedRef.current = true;
|
|
842
893
|
return function () {
|
|
843
894
|
isMountedRef.current = false;
|
|
844
895
|
};
|
|
845
896
|
}, []);
|
|
846
897
|
return useSyncExternalStore(React.useCallback(function (forceUpdate) {
|
|
898
|
+
clearTimeout(subscribeTimeoutRef.current);
|
|
847
899
|
function handleUpdate() {
|
|
848
900
|
var previousResult = resultRef.current;
|
|
849
901
|
var result = observable.getCurrentResult();
|
|
@@ -857,12 +909,20 @@ function useObservableQueryResult(observable) {
|
|
|
857
909
|
forceUpdate();
|
|
858
910
|
}
|
|
859
911
|
}
|
|
860
|
-
var subscription
|
|
861
|
-
|
|
862
|
-
|
|
912
|
+
var subscription;
|
|
913
|
+
subscribeTimeoutRef.current = setTimeout(function () {
|
|
914
|
+
subscription = observable.subscribe({
|
|
915
|
+
next: handleUpdate,
|
|
916
|
+
error: handleUpdate,
|
|
917
|
+
});
|
|
918
|
+
var result = resultRef.current;
|
|
919
|
+
if (result.networkStatus !== observable['queryInfo'].networkStatus &&
|
|
920
|
+
result.networkStatus === core.NetworkStatus.ready) {
|
|
921
|
+
observable['queryInfo'].markReady();
|
|
922
|
+
}
|
|
863
923
|
});
|
|
864
924
|
return function () {
|
|
865
|
-
subscription.unsubscribe();
|
|
925
|
+
subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe();
|
|
866
926
|
};
|
|
867
927
|
}, [observable]), function () { return resultRef.current; }, function () { return resultRef.current; });
|
|
868
928
|
}
|