@apollo/client 3.5.0 → 3.6.0-beta.1

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.
Files changed (132) hide show
  1. package/README.md +1 -1
  2. package/apollo-client.cjs +153 -178
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/core/cache.js +2 -2
  6. package/cache/inmemory/entityStore.js +4 -4
  7. package/cache/inmemory/inMemoryCache.js +3 -3
  8. package/cache/inmemory/object-canon.js +2 -2
  9. package/cache/inmemory/policies.js +1 -1
  10. package/cache/inmemory/reactiveVars.js +2 -2
  11. package/cache/inmemory/readFromStore.js +2 -2
  12. package/cache/inmemory/writeToStore.js +3 -3
  13. package/config/jest/setup.js +1 -1
  14. package/core/ApolloClient.d.ts +0 -1
  15. package/core/ApolloClient.d.ts.map +1 -1
  16. package/core/ApolloClient.js +1 -1
  17. package/core/LocalState.js +2 -2
  18. package/core/ObservableQuery.d.ts +0 -1
  19. package/core/ObservableQuery.d.ts.map +1 -1
  20. package/core/ObservableQuery.js +2 -2
  21. package/core/QueryInfo.d.ts +2 -2
  22. package/core/QueryInfo.d.ts.map +1 -1
  23. package/core/QueryInfo.js +2 -2
  24. package/core/QueryManager.d.ts +0 -1
  25. package/core/QueryManager.d.ts.map +1 -1
  26. package/core/QueryManager.js +2 -2
  27. package/core/core.cjs +1 -1
  28. package/core/core.cjs.map +1 -1
  29. package/core/index.js +2 -2
  30. package/errors/index.js +1 -1
  31. package/invariantErrorCodes.js +1 -1
  32. package/link/batch/batchLink.d.ts +0 -1
  33. package/link/batch/batchLink.d.ts.map +1 -1
  34. package/link/batch/batchLink.js +1 -1
  35. package/link/batch/batching.d.ts +0 -1
  36. package/link/batch/batching.d.ts.map +1 -1
  37. package/link/batch/batching.js +1 -1
  38. package/link/batch-http/batchHttpLink.d.ts +0 -1
  39. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  40. package/link/batch-http/batchHttpLink.js +1 -1
  41. package/link/context/index.js +1 -1
  42. package/link/core/ApolloLink.d.ts +0 -1
  43. package/link/core/ApolloLink.d.ts.map +1 -1
  44. package/link/core/ApolloLink.js +1 -1
  45. package/link/core/types.d.ts +0 -1
  46. package/link/core/types.d.ts.map +1 -1
  47. package/link/error/index.d.ts +0 -1
  48. package/link/error/index.d.ts.map +1 -1
  49. package/link/error/index.js +1 -1
  50. package/link/http/HttpLink.js +1 -1
  51. package/link/http/createHttpLink.js +2 -2
  52. package/link/http/selectHttpOptionsAndBody.js +2 -2
  53. package/link/persisted-queries/index.js +2 -2
  54. package/link/retry/retryLink.d.ts +0 -1
  55. package/link/retry/retryLink.d.ts.map +1 -1
  56. package/link/retry/retryLink.js +1 -1
  57. package/link/schema/index.d.ts +0 -1
  58. package/link/schema/index.d.ts.map +1 -1
  59. package/link/schema/index.js +2 -2
  60. package/link/utils/createOperation.js +1 -1
  61. package/link/utils/fromError.d.ts +0 -1
  62. package/link/utils/fromError.d.ts.map +1 -1
  63. package/link/utils/fromPromise.d.ts +0 -1
  64. package/link/utils/fromPromise.d.ts.map +1 -1
  65. package/link/utils/toPromise.d.ts +0 -1
  66. package/link/utils/toPromise.d.ts.map +1 -1
  67. package/link/ws/index.d.ts +0 -1
  68. package/link/ws/index.d.ts.map +1 -1
  69. package/link/ws/index.js +2 -2
  70. package/package.json +12 -8
  71. package/react/components/Mutation.js +1 -1
  72. package/react/components/Query.js +2 -2
  73. package/react/components/Subscription.js +1 -1
  74. package/react/context/ApolloConsumer.js +1 -1
  75. package/react/context/ApolloContext.js +1 -1
  76. package/react/context/ApolloProvider.js +1 -1
  77. package/react/hoc/hoc-utils.js +2 -2
  78. package/react/hoc/mutation-hoc.js +3 -3
  79. package/react/hoc/query-hoc.js +3 -3
  80. package/react/hoc/subscription-hoc.js +3 -3
  81. package/react/hoc/withApollo.js +3 -3
  82. package/react/hooks/hooks.cjs +149 -174
  83. package/react/hooks/hooks.cjs.map +1 -1
  84. package/react/hooks/useApolloClient.js +1 -1
  85. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  86. package/react/hooks/useLazyQuery.js +2 -2
  87. package/react/hooks/useLazyQuery.js.map +1 -1
  88. package/react/hooks/useMutation.d.ts.map +1 -1
  89. package/react/hooks/useMutation.js +70 -54
  90. package/react/hooks/useMutation.js.map +1 -1
  91. package/react/hooks/useQuery.d.ts.map +1 -1
  92. package/react/hooks/useQuery.js +85 -126
  93. package/react/hooks/useQuery.js.map +1 -1
  94. package/react/hooks/useReactiveVar.js +1 -1
  95. package/react/hooks/useSubscription.js +2 -2
  96. package/react/ssr/RenderPromises.d.ts +2 -2
  97. package/react/ssr/RenderPromises.d.ts.map +1 -1
  98. package/react/ssr/RenderPromises.js +5 -7
  99. package/react/ssr/RenderPromises.js.map +1 -1
  100. package/react/ssr/getDataFromTree.js +2 -2
  101. package/react/ssr/ssr.cjs +5 -7
  102. package/react/ssr/ssr.cjs.map +1 -1
  103. package/react/types/types.d.ts +0 -1
  104. package/react/types/types.d.ts.map +1 -1
  105. package/testing/core/mocking/mockFetch.js +2 -2
  106. package/testing/core/mocking/mockLink.d.ts +0 -1
  107. package/testing/core/mocking/mockLink.d.ts.map +1 -1
  108. package/testing/core/mocking/mockLink.js +3 -3
  109. package/testing/core/mocking/mockSubscriptionLink.d.ts +0 -1
  110. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -1
  111. package/testing/core/mocking/mockSubscriptionLink.js +1 -1
  112. package/testing/core/mocking/mockWatchQuery.js +1 -1
  113. package/testing/core/observableToPromise.js +1 -1
  114. package/testing/react/MockedProvider.js +2 -2
  115. package/utilities/common/mergeDeep.js +1 -1
  116. package/utilities/globals/fix-graphql.js +2 -2
  117. package/utilities/globals/index.js +1 -1
  118. package/utilities/graphql/directives.js +1 -1
  119. package/utilities/graphql/fragments.d.ts.map +1 -1
  120. package/utilities/graphql/fragments.js +1 -1
  121. package/utilities/graphql/fragments.js.map +1 -1
  122. package/utilities/graphql/transform.js +2 -2
  123. package/utilities/observables/Concast.d.ts +0 -1
  124. package/utilities/observables/Concast.d.ts.map +1 -1
  125. package/utilities/observables/Concast.js +1 -1
  126. package/utilities/observables/Observable.js +2 -2
  127. package/utilities/observables/asyncMap.d.ts +0 -1
  128. package/utilities/observables/asyncMap.d.ts.map +1 -1
  129. package/utilities/observables/subclassing.d.ts +0 -1
  130. package/utilities/observables/subclassing.d.ts.map +1 -1
  131. package/utilities/policies/pagination.js +2 -2
  132. package/version.js +1 -1
package/README.md CHANGED
@@ -31,7 +31,7 @@ Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apo
31
31
  [Apollo](https://apollographql.com/) builds open-source software and a graph platform to unify GraphQL across your apps and services. We help you ship faster with:
32
32
 
33
33
  * [Apollo Studio](https://www.apollographql.com/studio/develop/) – A free, end-to-end platform for managing your GraphQL lifecycle. Track your GraphQL schemas in a hosted registry to create a source of truth for everything in your graph. Studio provides an IDE (Apollo Explorer) so you can explore data, collaborate on queries, observe usage, and safely make schema changes.
34
- * [Apollo Federation](https://www.apollographql.com/apollo-federation) – The industry-standard open architecture for building a distributed graph. Use Apollo’s open-source gateway to compose a unified graph from multiple subgraphs, determine a query plan, and route requests across your services.
34
+ * [Apollo Federation](https://www.apollographql.com/apollo-federation) – The industry-standard open architecture for building a distributed graph. Use Apollo’s gateway to compose a unified graph from multiple subgraphs, determine a query plan, and route requests across your services.
35
35
  * [Apollo Client](https://www.apollographql.com/apollo-client/) – The most popular GraphQL client for the web. Apollo also builds and maintains [Apollo iOS](https://github.com/apollographql/apollo-ios) and [Apollo Android](https://github.com/apollographql/apollo-android).
36
36
  * [Apollo Server](https://www.apollographql.com/docs/apollo-server/) – A production-ready JavaScript GraphQL server that connects to any microservice, API, or database. Compatible with all popular JavaScript frameworks and deployable in serverless environments.
37
37
 
package/apollo-client.cjs CHANGED
@@ -13,6 +13,7 @@ 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;
@@ -1291,7 +1292,7 @@ var concat = ApolloLink.concat;
1291
1292
 
1292
1293
  var execute = ApolloLink.execute;
1293
1294
 
1294
- var version = '3.5.0';
1295
+ var version = '3.6.0-beta.1';
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).catch(function () { });
6119
- nextResult = obsQuery.getCurrentResult();
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, { client: client, query: query, options: options });
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.useEffect(function () {
6142
- if (context.renderPromises) {
6143
- return;
6144
- }
6145
- var subscription = obsQuery.subscribe(onNext, onError);
6146
- function onNext() {
6147
- var _a, _b;
6148
- var previousResult = ref.current.result;
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
- subscription = obsQuery.subscribe(onNext, onError);
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
- if (!error.hasOwnProperty('graphQLErrors')) {
6176
- throw error;
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
- var previousResult = ref.current.result;
6179
- if ((previousResult && previousResult.loading) ||
6180
- !equality.equal(error, previousResult.error)) {
6181
- setResult(ref.current.result = {
6182
- data: previousResult.data,
6183
- error: error,
6184
- loading: false,
6185
- networkStatus: exports.NetworkStatus.error,
6186
- });
6187
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
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
- return function () { return subscription.unsubscribe(); };
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
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
6205
- !(options === null || options === void 0 ? void 0 : options.skip) &&
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
- if ((context.renderPromises || client.disableNetworkFetches) &&
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;
@@ -6323,63 +6282,79 @@ function useMutation(mutation, options) {
6323
6282
  result: result,
6324
6283
  mutationId: 0,
6325
6284
  isMounted: true,
6285
+ execute: null,
6286
+ client: client,
6287
+ mutation: mutation,
6288
+ options: options,
6326
6289
  });
6327
- var execute = React.useCallback(function (executeOptions) {
6328
- if (executeOptions === void 0) { executeOptions = {}; }
6329
- var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
6330
- if (!ref.current.result.loading && !baseOptions.ignoreResults) {
6331
- setResult(ref.current.result = {
6332
- loading: true,
6333
- error: void 0,
6334
- data: void 0,
6335
- called: true,
6336
- client: client,
6337
- });
6338
- }
6339
- var mutationId = ++ref.current.mutationId;
6340
- var clientOptions = mergeOptions(baseOptions, executeOptions);
6341
- return client.mutate(clientOptions).then(function (response) {
6342
- var _a;
6343
- var data = response.data, errors = response.errors;
6344
- var error = errors && errors.length > 0
6345
- ? new ApolloError({ graphQLErrors: errors })
6346
- : void 0;
6347
- if (mutationId === ref.current.mutationId &&
6348
- !baseOptions.ignoreResults) {
6349
- var result_1 = {
6350
- called: true,
6351
- loading: false,
6352
- data: data,
6353
- error: error,
6354
- client: client,
6355
- };
6356
- if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6357
- setResult(ref.current.result = result_1);
6358
- }
6359
- }
6360
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6361
- return response;
6362
- }).catch(function (error) {
6363
- if (mutationId === ref.current.mutationId &&
6364
- ref.current.isMounted) {
6365
- var result_2 = {
6366
- loading: false,
6367
- error: error,
6290
+ var execute = React.useMemo(function () {
6291
+ if (ref.current.execute != null &&
6292
+ ref.current.client === client &&
6293
+ equality.equal(options, ref.current.options) &&
6294
+ equality.equal(mutation, ref.current.mutation)) {
6295
+ return ref.current.execute;
6296
+ }
6297
+ ref.current.client = client;
6298
+ ref.current.options = options;
6299
+ ref.current.mutation = mutation;
6300
+ ref.current.execute = function (executeOptions) {
6301
+ if (executeOptions === void 0) { executeOptions = {}; }
6302
+ var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
6303
+ if (!ref.current.result.loading && !baseOptions.ignoreResults) {
6304
+ setResult(ref.current.result = {
6305
+ loading: true,
6306
+ error: void 0,
6368
6307
  data: void 0,
6369
6308
  called: true,
6370
6309
  client: client,
6371
- };
6372
- if (!equality.equal(ref.current.result, result_2)) {
6373
- setResult(ref.current.result = result_2);
6374
- }
6375
- }
6376
- if (baseOptions.onError) {
6377
- baseOptions.onError(error);
6378
- return { data: void 0, errors: error };
6310
+ });
6379
6311
  }
6380
- throw error;
6381
- });
6382
- }, [client, options, mutation]);
6312
+ var mutationId = ++ref.current.mutationId;
6313
+ var clientOptions = mergeOptions(baseOptions, executeOptions);
6314
+ return client.mutate(clientOptions).then(function (response) {
6315
+ var _a;
6316
+ var data = response.data, errors = response.errors;
6317
+ var error = errors && errors.length > 0
6318
+ ? new ApolloError({ graphQLErrors: errors })
6319
+ : void 0;
6320
+ if (mutationId === ref.current.mutationId &&
6321
+ !baseOptions.ignoreResults) {
6322
+ var result_1 = {
6323
+ called: true,
6324
+ loading: false,
6325
+ data: data,
6326
+ error: error,
6327
+ client: client,
6328
+ };
6329
+ if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6330
+ setResult(ref.current.result = result_1);
6331
+ }
6332
+ }
6333
+ (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6334
+ return response;
6335
+ }).catch(function (error) {
6336
+ if (mutationId === ref.current.mutationId &&
6337
+ ref.current.isMounted) {
6338
+ var result_2 = {
6339
+ loading: false,
6340
+ error: error,
6341
+ data: void 0,
6342
+ called: true,
6343
+ client: client,
6344
+ };
6345
+ if (!equality.equal(ref.current.result, result_2)) {
6346
+ setResult(ref.current.result = result_2);
6347
+ }
6348
+ }
6349
+ if (baseOptions.onError) {
6350
+ baseOptions.onError(error);
6351
+ return { data: void 0, errors: error };
6352
+ }
6353
+ throw error;
6354
+ });
6355
+ };
6356
+ return ref.current.execute;
6357
+ }, [client, mutation, options]);
6383
6358
  var reset = React.useCallback(function () {
6384
6359
  setResult({ called: false, loading: false, client: client });
6385
6360
  }, []);