@apollo/client 3.5.1 → 3.5.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 CHANGED
@@ -1291,7 +1291,7 @@ var concat = ApolloLink.concat;
1291
1291
 
1292
1292
  var execute = ApolloLink.execute;
1293
1293
 
1294
- var version = '3.5.1';
1294
+ var version = '3.5.2';
1295
1295
 
1296
1296
  var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1297
1297
  function parseAndCheckHttpResponse(operations) {
@@ -6323,63 +6323,79 @@ function useMutation(mutation, options) {
6323
6323
  result: result,
6324
6324
  mutationId: 0,
6325
6325
  isMounted: true,
6326
+ execute: null,
6327
+ client: client,
6328
+ mutation: mutation,
6329
+ options: options,
6326
6330
  });
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,
6331
+ var execute = React.useMemo(function () {
6332
+ if (ref.current.execute != null &&
6333
+ ref.current.client === client &&
6334
+ equality.equal(options, ref.current.options) &&
6335
+ equality.equal(mutation, ref.current.mutation)) {
6336
+ return ref.current.execute;
6337
+ }
6338
+ ref.current.client = client;
6339
+ ref.current.options = options;
6340
+ ref.current.mutation = mutation;
6341
+ ref.current.execute = function (executeOptions) {
6342
+ if (executeOptions === void 0) { executeOptions = {}; }
6343
+ var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
6344
+ if (!ref.current.result.loading && !baseOptions.ignoreResults) {
6345
+ setResult(ref.current.result = {
6346
+ loading: true,
6347
+ error: void 0,
6368
6348
  data: void 0,
6369
6349
  called: true,
6370
6350
  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 };
6351
+ });
6379
6352
  }
6380
- throw error;
6381
- });
6382
- }, [client, options, mutation]);
6353
+ var mutationId = ++ref.current.mutationId;
6354
+ var clientOptions = mergeOptions(baseOptions, executeOptions);
6355
+ return client.mutate(clientOptions).then(function (response) {
6356
+ var _a;
6357
+ var data = response.data, errors = response.errors;
6358
+ var error = errors && errors.length > 0
6359
+ ? new ApolloError({ graphQLErrors: errors })
6360
+ : void 0;
6361
+ if (mutationId === ref.current.mutationId &&
6362
+ !baseOptions.ignoreResults) {
6363
+ var result_1 = {
6364
+ called: true,
6365
+ loading: false,
6366
+ data: data,
6367
+ error: error,
6368
+ client: client,
6369
+ };
6370
+ if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
6371
+ setResult(ref.current.result = result_1);
6372
+ }
6373
+ }
6374
+ (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
6375
+ return response;
6376
+ }).catch(function (error) {
6377
+ if (mutationId === ref.current.mutationId &&
6378
+ ref.current.isMounted) {
6379
+ var result_2 = {
6380
+ loading: false,
6381
+ error: error,
6382
+ data: void 0,
6383
+ called: true,
6384
+ client: client,
6385
+ };
6386
+ if (!equality.equal(ref.current.result, result_2)) {
6387
+ setResult(ref.current.result = result_2);
6388
+ }
6389
+ }
6390
+ if (baseOptions.onError) {
6391
+ baseOptions.onError(error);
6392
+ return { data: void 0, errors: error };
6393
+ }
6394
+ throw error;
6395
+ });
6396
+ };
6397
+ return ref.current.execute;
6398
+ }, [client, mutation, options]);
6383
6399
  var reset = React.useCallback(function () {
6384
6400
  setResult({ called: false, loading: false, client: client });
6385
6401
  }, []);