@apollo/client 3.7.0-alpha.5 → 3.7.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 (56) hide show
  1. package/apollo-client.cjs +94 -37
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +21 -12
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +21 -12
  7. package/cache/core/types/Cache.d.ts +2 -2
  8. package/cache/core/types/Cache.d.ts.map +1 -1
  9. package/cache/core/types/Cache.js.map +1 -1
  10. package/cache/core/types/common.d.ts +1 -0
  11. package/cache/core/types/common.d.ts.map +1 -1
  12. package/cache/core/types/common.js +10 -0
  13. package/cache/core/types/common.js.map +1 -1
  14. package/cache/index.d.ts +1 -1
  15. package/cache/index.d.ts.map +1 -1
  16. package/cache/index.js.map +1 -1
  17. package/cache/inmemory/inMemoryCache.js +2 -2
  18. package/cache/inmemory/inMemoryCache.js.map +1 -1
  19. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  20. package/cache/inmemory/readFromStore.js +10 -11
  21. package/cache/inmemory/readFromStore.js.map +1 -1
  22. package/core/ObservableQuery.d.ts.map +1 -1
  23. package/core/ObservableQuery.js +2 -2
  24. package/core/ObservableQuery.js.map +1 -1
  25. package/core/core.cjs +2 -2
  26. package/core/core.cjs.map +1 -1
  27. package/core/core.cjs.native.js +2 -2
  28. package/invariantErrorCodes.js +1 -1
  29. package/package.json +7 -7
  30. package/react/hooks/hooks.cjs +63 -12
  31. package/react/hooks/hooks.cjs.map +1 -1
  32. package/react/hooks/hooks.cjs.native.js +63 -12
  33. package/react/hooks/index.d.ts +1 -0
  34. package/react/hooks/index.d.ts.map +1 -1
  35. package/react/hooks/index.js +1 -0
  36. package/react/hooks/index.js.map +1 -1
  37. package/react/hooks/useFragment.d.ts +14 -0
  38. package/react/hooks/useFragment.d.ts.map +1 -0
  39. package/react/hooks/useFragment.js +37 -0
  40. package/react/hooks/useFragment.js.map +1 -0
  41. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  42. package/react/hooks/useLazyQuery.js +5 -1
  43. package/react/hooks/useLazyQuery.js.map +1 -1
  44. package/react/hooks/useMutation.js +7 -7
  45. package/react/hooks/useMutation.js.map +1 -1
  46. package/react/hooks/useQuery.d.ts +2 -1
  47. package/react/hooks/useQuery.d.ts.map +1 -1
  48. package/react/hooks/useQuery.js +21 -5
  49. package/react/hooks/useQuery.js.map +1 -1
  50. package/utilities/common/mergeDeep.d.ts.map +1 -1
  51. package/utilities/common/mergeDeep.js +8 -11
  52. package/utilities/common/mergeDeep.js.map +1 -1
  53. package/utilities/utilities.cjs +8 -11
  54. package/utilities/utilities.cjs.map +1 -1
  55. package/utilities/utilities.cjs.native.js +8 -11
  56. package/version.js +1 -1
@@ -90,7 +90,7 @@ function useInternalState(client, query) {
90
90
  if (!stateRef.current ||
91
91
  client !== stateRef.current.client ||
92
92
  query !== stateRef.current.query) {
93
- stateRef.current = new InternalState(client, query);
93
+ stateRef.current = new InternalState(client, query, stateRef.current);
94
94
  }
95
95
  var state = stateRef.current;
96
96
  var _a = React.useState(0); _a[0]; var setTick = _a[1];
@@ -100,7 +100,7 @@ function useInternalState(client, query) {
100
100
  return state;
101
101
  }
102
102
  var InternalState = (function () {
103
- function InternalState(client, query) {
103
+ function InternalState(client, query, previous) {
104
104
  this.client = client;
105
105
  this.query = query;
106
106
  this.asyncResolveFns = new Set();
@@ -119,6 +119,11 @@ var InternalState = (function () {
119
119
  });
120
120
  this.toQueryResultCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
121
121
  parser.verifyDocumentType(query, parser.DocumentType.Query);
122
+ var previousResult = previous && previous.result;
123
+ var previousData = previousResult && previousResult.data;
124
+ if (previousData) {
125
+ this.previousData = previousData;
126
+ }
122
127
  }
123
128
  InternalState.prototype.forceUpdate = function () {
124
129
  __DEV__ && globals.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
@@ -200,7 +205,7 @@ var InternalState = (function () {
200
205
  this.watchQueryOptions = watchQueryOptions;
201
206
  if (currentWatchQueryOptions && this.observable) {
202
207
  this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
203
- this.observable.reobserve(watchQueryOptions);
208
+ this.observable.reobserve(this.getObsQueryOptions());
204
209
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
205
210
  this.result = void 0;
206
211
  }
@@ -221,6 +226,17 @@ var InternalState = (function () {
221
226
  this.result = void 0;
222
227
  }
223
228
  };
229
+ InternalState.prototype.getObsQueryOptions = function () {
230
+ var toMerge = [];
231
+ var globalDefaults = this.client.defaultOptions.watchQuery;
232
+ if (globalDefaults)
233
+ toMerge.push(globalDefaults);
234
+ if (this.queryHookOptions.defaultOptions) {
235
+ toMerge.push(this.queryHookOptions.defaultOptions);
236
+ }
237
+ toMerge.push(utilities.compact(this.observable && this.observable.options, this.watchQueryOptions));
238
+ return toMerge.reduce(core.mergeOptions);
239
+ };
224
240
  InternalState.prototype.createWatchQueryOptions = function (_a) {
225
241
  var _b;
226
242
  if (_a === void 0) { _a = {}; }
@@ -261,7 +277,7 @@ var InternalState = (function () {
261
277
  this.renderPromises
262
278
  && this.renderPromises.getSSRObservable(this.watchQueryOptions)
263
279
  || this.observable
264
- || this.client.watchQuery(core.mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
280
+ || this.client.watchQuery(this.getObsQueryOptions());
265
281
  this.obsQueryFields = React.useMemo(function () { return ({
266
282
  refetch: obsQuery.refetch.bind(obsQuery),
267
283
  reobserve: obsQuery.reobserve.bind(obsQuery),
@@ -344,7 +360,10 @@ var EAGER_METHODS = [
344
360
  function useLazyQuery(query, options) {
345
361
  var internalState = useInternalState(useApolloClient(options && options.client), query);
346
362
  var execOptionsRef = React.useRef();
347
- var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
363
+ var merged = execOptionsRef.current
364
+ ? utilities.mergeOptions(options, execOptionsRef.current)
365
+ : options;
366
+ var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
348
367
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
349
368
  internalState.getDefaultFetchPolicy();
350
369
  var result = Object.assign(useQueryResult, {
@@ -417,7 +436,7 @@ function useMutation(mutation, options) {
417
436
  var mutationId = ++ref.current.mutationId;
418
437
  var clientOptions = core.mergeOptions(baseOptions, executeOptions);
419
438
  return client.mutate(clientOptions).then(function (response) {
420
- var _a, _b;
439
+ var _a, _b, _c;
421
440
  var data = response.data, errors$1 = response.errors;
422
441
  var error = errors$1 && errors$1.length > 0
423
442
  ? new errors.ApolloError({ graphQLErrors: errors$1 })
@@ -435,11 +454,11 @@ function useMutation(mutation, options) {
435
454
  setResult(ref.current.result = result_1);
436
455
  }
437
456
  }
438
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
439
- (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
457
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data);
458
+ (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data);
440
459
  return response;
441
460
  }).catch(function (error) {
442
- var _a, _b;
461
+ var _a, _b, _c, _d;
443
462
  if (mutationId === ref.current.mutationId &&
444
463
  ref.current.isMounted) {
445
464
  var result_2 = {
@@ -453,9 +472,9 @@ function useMutation(mutation, options) {
453
472
  setResult(ref.current.result = result_2);
454
473
  }
455
474
  }
456
- if (baseOptions.onError || clientOptions.onError) {
457
- (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
458
- (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
475
+ if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
476
+ (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error);
477
+ (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error);
459
478
  return { data: void 0, errors: error };
460
479
  }
461
480
  throw error;
@@ -595,7 +614,39 @@ function useReactiveVar(rv) {
595
614
  return value;
596
615
  }
597
616
 
617
+ function useFragment(options) {
618
+ var cache = useApolloClient().cache;
619
+ var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
620
+ var diffOptions = tslib.__assign(tslib.__assign({}, rest), { id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
621
+ var resultRef = React.useRef();
622
+ var latestDiff = cache.diff(diffOptions);
623
+ return useSyncExternalStore(function (forceUpdate) {
624
+ var immediate = true;
625
+ return cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: immediate, callback: function (diff) {
626
+ if (!immediate && !equality.equal(diff, latestDiff)) {
627
+ resultRef.current = diffToResult(latestDiff = diff);
628
+ forceUpdate();
629
+ }
630
+ immediate = false;
631
+ } }));
632
+ }, function () {
633
+ return resultRef.current ||
634
+ (resultRef.current = diffToResult(latestDiff));
635
+ });
636
+ }
637
+ function diffToResult(diff) {
638
+ var result = {
639
+ data: diff.result,
640
+ complete: !!diff.complete,
641
+ };
642
+ if (diff.missing) {
643
+ result.missing = utilities.mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
644
+ }
645
+ return result;
646
+ }
647
+
598
648
  exports.useApolloClient = useApolloClient;
649
+ exports.useFragment = useFragment;
599
650
  exports.useLazyQuery = useLazyQuery;
600
651
  exports.useMutation = useMutation;
601
652
  exports.useQuery = useQuery;
@@ -5,4 +5,5 @@ export * from './useMutation';
5
5
  export { useQuery } from './useQuery';
6
6
  export * from './useSubscription';
7
7
  export * from './useReactiveVar';
8
+ export * from './useFragment';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
@@ -5,4 +5,5 @@ export * from "./useMutation.js";
5
5
  export { useQuery } from "./useQuery.js";
6
6
  export * from "./useSubscription.js";
7
7
  export * from "./useReactiveVar.js";
8
+ export * from "./useFragment.js";
8
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC","sourcesContent":["import '../../utilities/globals';\n\nexport * from './useApolloClient';\nexport * from './useLazyQuery';\nexport * from './useMutation';\nexport { useQuery } from './useQuery';\nexport * from './useSubscription';\nexport * from './useReactiveVar';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC","sourcesContent":["import '../../utilities/globals';\n\nexport * from './useApolloClient';\nexport * from './useLazyQuery';\nexport * from './useMutation';\nexport { useQuery } from './useQuery';\nexport * from './useSubscription';\nexport * from './useReactiveVar';\nexport * from './useFragment';\n"]}
@@ -0,0 +1,14 @@
1
+ import { Cache, Reference, StoreObject, MissingTree } from "../../cache";
2
+ export interface UseFragmentOptions<TData, TVars> extends Omit<Cache.DiffOptions<TData, TVars>, "id" | "query" | "optimistic">, Omit<Cache.ReadFragmentOptions<TData, TVars>, "id"> {
3
+ from: StoreObject | Reference | string;
4
+ optimistic?: boolean;
5
+ }
6
+ export interface UseFragmentResult<TData> {
7
+ data: TData | undefined;
8
+ complete: boolean;
9
+ missing?: MissingTree;
10
+ previousResult?: UseFragmentResult<TData>;
11
+ lastCompleteResult?: UseFragmentResult<TData>;
12
+ }
13
+ export declare function useFragment<TData, TVars>(options: UseFragmentOptions<TData, TVars>): UseFragmentResult<TData>;
14
+ //# sourceMappingURL=useFragment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFragment.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAChD,SAAQ,IAAI,CACV,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,EAC7B,IAAI,GACJ,OAAO,GACP,YAAY,CACf,EAAE,IAAI,CACL,KAAK,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,EACrC,IAAI,CACP;IACC,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC;IAEvC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAiBD,MAAM,WAAW,iBAAiB,CAAC,KAAK;IACtC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,cAAc,CAAC,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC1C,kBAAkB,CAAC,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC;CAC/C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EACtC,OAAO,EAAE,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,GACxC,iBAAiB,CAAC,KAAK,CAAC,CA0C1B"}
@@ -0,0 +1,37 @@
1
+ import { __assign, __rest } from "tslib";
2
+ import { useRef } from "react";
3
+ import { equal } from "@wry/equality";
4
+ import { mergeDeepArray } from "../../utilities/index.js";
5
+ import { useApolloClient } from "./useApolloClient.js";
6
+ import { useSyncExternalStore } from "./useSyncExternalStore.js";
7
+ export function useFragment(options) {
8
+ var cache = useApolloClient().cache;
9
+ var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = __rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
10
+ var diffOptions = __assign(__assign({}, rest), { id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
11
+ var resultRef = useRef();
12
+ var latestDiff = cache.diff(diffOptions);
13
+ return useSyncExternalStore(function (forceUpdate) {
14
+ var immediate = true;
15
+ return cache.watch(__assign(__assign({}, diffOptions), { immediate: immediate, callback: function (diff) {
16
+ if (!immediate && !equal(diff, latestDiff)) {
17
+ resultRef.current = diffToResult(latestDiff = diff);
18
+ forceUpdate();
19
+ }
20
+ immediate = false;
21
+ } }));
22
+ }, function () {
23
+ return resultRef.current ||
24
+ (resultRef.current = diffToResult(latestDiff));
25
+ });
26
+ }
27
+ function diffToResult(diff) {
28
+ var result = {
29
+ data: diff.result,
30
+ complete: !!diff.complete,
31
+ };
32
+ if (diff.missing) {
33
+ result.missing = mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
34
+ }
35
+ return result;
36
+ }
37
+ //# sourceMappingURL=useFragment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAQjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAwC9D,MAAM,UAAU,WAAW,CACzB,OAAyC;IAEjC,IAAA,KAAK,GAAK,eAAe,EAAE,MAAtB,CAAuB;IAGlC,IAAA,QAAQ,GAKN,OAAO,SALD,EACR,YAAY,GAIV,OAAO,aAJG,EACZ,IAAI,GAGF,OAAO,KAHL,EACJ,KAEE,OAAO,WAFQ,EAAjB,UAAU,mBAAG,IAAI,KAAA,EACd,IAAI,UACL,OAAO,EANL,kDAML,CADQ,CACG;IAEZ,IAAM,WAAW,yBACZ,IAAI,KACP,EAAE,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC1D,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE,YAAY,CAAC,EACtD,UAAU,YAAA,GACX,CAAC;IAEF,IAAM,SAAS,GAAG,MAAM,EAA4B,CAAC;IACrD,IAAI,UAAU,GAAG,KAAK,CAAC,IAAI,CAAQ,WAAW,CAAC,CAAC;IAEhD,OAAO,oBAAoB,CACzB,UAAA,WAAW;QACT,IAAI,SAAS,GAAG,IAAI,CAAC;QACrB,OAAO,KAAK,CAAC,KAAK,uBACb,WAAW,KACd,SAAS,WAAA,EACT,QAAQ,YAAC,IAAI;gBACX,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE;oBAC1C,SAAS,CAAC,OAAO,GAAG,YAAY,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;oBACpD,WAAW,EAAE,CAAC;iBACf;gBACD,SAAS,GAAG,KAAK,CAAC;YACpB,CAAC,IACD,CAAC;IACL,CAAC,EAED;QACE,OAAO,SAAS,CAAC,OAAO;YACtB,CAAC,SAAS,CAAC,OAAO,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC;IACnD,CAAC,CACF,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAA6B;IAE7B,IAAM,MAAM,GAA6B;QACvC,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;KAC1B,CAAC;IAEF,IAAI,IAAI,CAAC,OAAO,EAAE;QAChB,MAAM,CAAC,OAAO,GAAG,cAAc,CAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CACzC,CAAC;KACH;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { useRef } from \"react\";\nimport { equal } from \"@wry/equality\";\n\nimport { mergeDeepArray } from \"../../utilities\";\nimport {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache\";\n\nimport { useApolloClient } from \"./useApolloClient\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\n\nexport interface UseFragmentOptions<TData, TVars>\nextends Omit<\n Cache.DiffOptions<TData, TVars>,\n | \"id\"\n | \"query\"\n | \"optimistic\"\n>, Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n | \"id\"\n> {\n from: StoreObject | Reference | string;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n}\n\n// Since the above definition of UseFragmentOptions can be hard to parse without\n// help from TypeScript/VSCode, here are the intended fields and their types.\n// Uncomment this code to check that it's consistent with the definition above.\n//\n// export interface UseFragmentOptions<TData, TVars> {\n// from: string | StoreObject | Reference;\n// fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\n// fragmentName?: string;\n// optimistic?: boolean;\n// variables?: TVars;\n// previousResult?: any;\n// returnPartialData?: boolean;\n// canonizeResults?: boolean;\n// }\n\nexport interface UseFragmentResult<TData> {\n data: TData | undefined;\n complete: boolean;\n missing?: MissingTree;\n previousResult?: UseFragmentResult<TData>;\n lastCompleteResult?: UseFragmentResult<TData>;\n}\n\nexport function useFragment<TData, TVars>(\n options: UseFragmentOptions<TData, TVars>,\n): UseFragmentResult<TData> {\n const { cache } = useApolloClient();\n\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...rest\n } = options;\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...rest,\n id: typeof from === \"string\" ? from : cache.identify(from),\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n };\n\n const resultRef = useRef<UseFragmentResult<TData>>();\n let latestDiff = cache.diff<TData>(diffOptions);\n\n return useSyncExternalStore(\n forceUpdate => {\n let immediate = true;\n return cache.watch({\n ...diffOptions,\n immediate,\n callback(diff) {\n if (!immediate && !equal(diff, latestDiff)) {\n resultRef.current = diffToResult(latestDiff = diff);\n forceUpdate();\n }\n immediate = false;\n },\n });\n },\n\n () => {\n return resultRef.current ||\n (resultRef.current = diffToResult(latestDiff));\n },\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>,\n): UseFragmentResult<TData> {\n const result: UseFragmentResult<TData> = {\n data: diff.result,\n complete: !!diff.complete,\n };\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map(error => error.missing),\n );\n }\n\n return result;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EAErB,MAAM,gBAAgB,CAAC;AAexB,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,kBAAkB,EACvE,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,GAChD,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAiEzC"}
1
+ {"version":3,"file":"useLazyQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EAErB,MAAM,gBAAgB,CAAC;AAexB,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,kBAAkB,EACvE,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,GAChD,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAmEzC"}
@@ -1,5 +1,6 @@
1
1
  import { __assign } from "tslib";
2
2
  import { useCallback, useMemo, useRef } from 'react';
3
+ import { mergeOptions } from "../../utilities/index.js";
3
4
  import { useInternalState } from "./useQuery.js";
4
5
  import { useApolloClient } from "./useApolloClient.js";
5
6
  var EAGER_METHODS = [
@@ -13,7 +14,10 @@ var EAGER_METHODS = [
13
14
  export function useLazyQuery(query, options) {
14
15
  var internalState = useInternalState(useApolloClient(options && options.client), query);
15
16
  var execOptionsRef = useRef();
16
- var useQueryResult = internalState.useQuery(__assign(__assign(__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
17
+ var merged = execOptionsRef.current
18
+ ? mergeOptions(options, execOptionsRef.current)
19
+ : options;
20
+ var useQueryResult = internalState.useQuery(__assign(__assign({}, merged), { skip: !execOptionsRef.current }));
17
21
  var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
18
22
  internalState.getDefaultFetchPolicy();
19
23
  var result = Object.assign(useQueryResult, {
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAQrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,iBAAiB;CACT,CAAC;AAEX,MAAM,UAAU,YAAY,CAC1B,KAA0D,EAC1D,OAAiD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d,cAAc,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC,uBACpC,cAAc,KACjB,WAAW,EAAE,cAAc,CAAC,WAAW,IAAI,kBAAkB,IAC7D,CAAC,CAAC;YACF,WAAW,EAAE,kBAAkB;SAChC,CAAC;QAEF,IAAM,OAAO,GAAG,aAAa;aAC1B,WAAW,EAAE;aACb,IAAI,CAAC,UAAA,WAAW,IAAI,OAAA,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,EAAxC,CAAwC,CAAC,CAAC;QAIjE,OAAO,CAAC,KAAK,CAAC,cAAO,CAAC,CAAC,CAAC;QAExB,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { useCallback, useMemo, useRef } from 'react';\n\nimport { OperationVariables } from '../../core';\nimport {\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n QueryResult,\n} from '../types/types';\nimport { useInternalState } from './useQuery';\nimport { useApolloClient } from './useApolloClient';\n\n// The following methods, when called will execute the query, regardless of\n// whether the useLazyQuery execute function was called before.\nconst EAGER_METHODS = [\n 'refetch',\n 'reobserve',\n 'fetchMore',\n 'updateQuery',\n 'startPolling',\n 'subscribeToMore',\n] as const;\n\nexport function useLazyQuery<TData = any, TVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<TData, TVariables>\n): LazyQueryResultTuple<TData, TVariables> {\n const internalState = useInternalState(\n useApolloClient(options && options.client),\n query,\n );\n\n const execOptionsRef = useRef<Partial<LazyQueryHookOptions<TData, TVariables>>>();\n\n const useQueryResult = internalState.useQuery({\n ...options,\n ...execOptionsRef.current,\n skip: !execOptionsRef.current,\n });\n\n const initialFetchPolicy =\n useQueryResult.observable.options.initialFetchPolicy ||\n internalState.getDefaultFetchPolicy();\n\n const result: QueryResult<TData, TVariables> =\n Object.assign(useQueryResult, {\n called: !!execOptionsRef.current,\n });\n\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = result[key];\n eagerMethods[key] = function () {\n if (!execOptionsRef.current) {\n execOptionsRef.current = Object.create(null);\n // Only the first time populating execOptionsRef.current matters here.\n internalState.forceUpdate();\n }\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods;\n }, []);\n\n Object.assign(result, eagerMethods);\n\n const execute = useCallback<\n LazyQueryResultTuple<TData, TVariables>[0]\n >(executeOptions => {\n execOptionsRef.current = executeOptions ? {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n } : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const promise = internalState\n .asyncUpdate() // Like internalState.forceUpdate, but returns a Promise.\n .then(queryResult => Object.assign(queryResult, eagerMethods));\n\n // Because the return value of `useLazyQuery` is usually floated, we need\n // to catch the promise to prevent unhandled rejections.\n promise.catch(() => {});\n\n return promise;\n }, []);\n\n return [execute, result];\n}\n"]}
1
+ {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,iBAAiB;CACT,CAAC;AAEX,MAAM,UAAU,YAAY,CAC1B,KAA0D,EAC1D,OAAiD;IAEjD,IAAM,a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CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAEpC,IAAM,OAAO,GAAG,WAAW,CAEzB,UAAA,cAAc;QACd,cAAc,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC,uBACpC,cAAc,KACjB,WAAW,EAAE,cAAc,CAAC,WAAW,IAAI,kBAAkB,IAC7D,CAAC,CAAC;YACF,WAAW,EAAE,kBAAkB;SAChC,CAAC;QAEF,IAAM,OAAO,GAAG,aAAa;aAC1B,WAAW,EAAE;aACb,IAAI,CAAC,UAAA,WAAW,IAAI,OAAA,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,EAAxC,CAAwC,CAAC,CAAC;QAIjE,OAAO,CAAC,KAAK,CAAC,cAAO,CAAC,CAAC,CAAC;QAExB,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { useCallback, useMemo, useRef } from 'react';\n\nimport { OperationVariables } from '../../core';\nimport { mergeOptions } from '../../utilities';\nimport {\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n QueryResult,\n} from '../types/types';\nimport { useInternalState } from './useQuery';\nimport { useApolloClient } from './useApolloClient';\n\n// The following methods, when called will execute the query, regardless of\n// whether the useLazyQuery execute function was called before.\nconst EAGER_METHODS = [\n 'refetch',\n 'reobserve',\n 'fetchMore',\n 'updateQuery',\n 'startPolling',\n 'subscribeToMore',\n] as const;\n\nexport function useLazyQuery<TData = any, TVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<TData, TVariables>\n): LazyQueryResultTuple<TData, TVariables> {\n const internalState = useInternalState(\n useApolloClient(options && options.client),\n query,\n );\n\n const execOptionsRef = useRef<Partial<LazyQueryHookOptions<TData, TVariables>>>();\n const merged = execOptionsRef.current\n ? mergeOptions(options, execOptionsRef.current)\n : options;\n\n const useQueryResult = internalState.useQuery({\n ...merged,\n skip: !execOptionsRef.current,\n });\n\n const initialFetchPolicy =\n useQueryResult.observable.options.initialFetchPolicy ||\n internalState.getDefaultFetchPolicy();\n\n const result: QueryResult<TData, TVariables> =\n Object.assign(useQueryResult, {\n called: !!execOptionsRef.current,\n });\n\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = result[key];\n eagerMethods[key] = function () {\n if (!execOptionsRef.current) {\n execOptionsRef.current = Object.create(null);\n // Only the first time populating execOptionsRef.current matters here.\n internalState.forceUpdate();\n }\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods;\n }, []);\n\n Object.assign(result, eagerMethods);\n\n const execute = useCallback<\n LazyQueryResultTuple<TData, TVariables>[0]\n >(executeOptions => {\n execOptionsRef.current = executeOptions ? {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n } : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const promise = internalState\n .asyncUpdate() // Like internalState.forceUpdate, but returns a Promise.\n .then(queryResult => Object.assign(queryResult, eagerMethods));\n\n // Because the return value of `useLazyQuery` is usually floated, we need\n // to catch the promise to prevent unhandled rejections.\n promise.catch(() => {});\n\n return promise;\n }, []);\n\n return [execute, result];\n}\n"]}
@@ -40,7 +40,7 @@ export function useMutation(mutation, options) {
40
40
  var mutationId = ++ref.current.mutationId;
41
41
  var clientOptions = mergeOptions(baseOptions, executeOptions);
42
42
  return client.mutate(clientOptions).then(function (response) {
43
- var _a, _b;
43
+ var _a, _b, _c;
44
44
  var data = response.data, errors = response.errors;
45
45
  var error = errors && errors.length > 0
46
46
  ? new ApolloError({ graphQLErrors: errors })
@@ -58,11 +58,11 @@ export function useMutation(mutation, options) {
58
58
  setResult(ref.current.result = result_1);
59
59
  }
60
60
  }
61
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
62
- (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
61
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data);
62
+ (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data);
63
63
  return response;
64
64
  }).catch(function (error) {
65
- var _a, _b;
65
+ var _a, _b, _c, _d;
66
66
  if (mutationId === ref.current.mutationId &&
67
67
  ref.current.isMounted) {
68
68
  var result_2 = {
@@ -76,9 +76,9 @@ export function useMutation(mutation, options) {
76
76
  setResult(ref.current.result = result_2);
77
77
  }
78
78
  }
79
- if (baseOptions.onError || clientOptions.onError) {
80
- (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
81
- (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
79
+ if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
80
+ (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error);
81
+ (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error);
82
82
  return { data: void 0, errors: error };
83
83
  }
84
84
  throw error;
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAUjE,OAAO,EAGL,YAAY,GAEb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO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AC,UAAU;gBACrC,GAAG,CAAC,OAAO,CAAC,SAAS,EACrB;gBACA,IAAM,QAAM,GAAG;oBACb,OAAO,EAAE,KAAK;oBACd,KAAK,OAAA;oBACL,IAAI,EAAE,KAAK,CAAC;oBACZ,MAAM,EAAE,IAAI;oBACZ,MAAM,QAAA;iBACP,CAAC;gBAEF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,QAAM,CAAC,EAAE;oBACtC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,QAAM,CAAC,CAAC;iBACxC;aACF;YAED,IAAI,WAAW,CAAC,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE;gBAChD,MAAA,WAAW,CAAC,OAAO,4DAAG,KAAK,CAAC,CAAC;gBAC7B,MAAA,cAAc,CAAC,OAAO,+DAAG,KAAK,CAAC,CAAC;gBAEhC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;aACxC;YAED,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAM,KAAK,GAAG,WAAW,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IACvD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC;QACR,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAE7B,OAAO;YACL,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAChC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n} from '../types/types';\n\nimport {\n ApolloCache,\n DefaultContext,\n mergeOptions,\n OperationVariables,\n} from '../../core';\nimport { equal } from '@wry/equality';\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { ApolloError } from '../../errors';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useMutation<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: MutationHookOptions<TData, TVariables, TContext>,\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = useState<Omit<MutationResult, 'reset'>>({\n called: false,\n loading: false,\n client,\n });\n\n const ref = useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n // TODO: Trying to assign these in a useEffect or useLayoutEffect breaks\n // higher-order components.\n {\n Object.assign(ref.current, { client, options, mutation });\n }\n\n const execute = useCallback((\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const {client, options, mutation} = ref.current;\n const baseOptions = { ...options, mutation };\n if (!ref.current.result.loading && !baseOptions.ignoreResults) {\n setResult(ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n });\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(\n baseOptions,\n executeOptions as any,\n );\n\n return client.mutate(clientOptions).then((response) => {\n const { data, errors } = response;\n const error =\n errors && errors.length > 0\n ? new ApolloError({ graphQLErrors: errors })\n : void 0;\n\n if (\n mutationId === ref.current.mutationId &&\n !clientOptions.ignoreResults\n ) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n baseOptions.onCompleted?.(response.data!);\n executeOptions.onCompleted?.(response.data!);\n return response;\n }).catch((error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n if (baseOptions.onError || clientOptions.onError) {\n baseOptions.onError?.(error);\n executeOptions.onError?.(error);\n // TODO(brian): why are we returning this here???\n return { data: void 0, errors: error };\n }\n\n throw error;\n });\n }, []);\n\n const reset = useCallback(() => {\n setResult({ called: false, loading: false, client });\n }, []);\n\n useEffect(() => {\n ref.current.isMounted = true;\n\n return () => {\n ref.current.isMounted = false;\n };\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
1
+ {"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAUjE,OAAO,EAGL,YAAY,GAEb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,UAAU,WAAW,CAMzB,QAA6D,EAC7D,OAA0D;IAE1D,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,CAAC;IAChD,kBAAkB,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAA,KAAsB,QAAQ,CAAgC;QAClE,MAAM,EAAE,KAAK;QACb,OAAO,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GAAG,QAAM,CAAC,CAAC;iBACxC;aACF;YAED,IAAI,CAAA,MAAA,GAAG,CAAC,OAAO,CAAC,OAAO,0CAAE,OAAO,KAAI,aAAa,CAAC,OAAO,EAAE;gBACzD,MAAA,MAAA,GAAG,CAAC,OAAO,CAAC,OAAO,0CAAE,OAAO,mDAAG,KAAK,CAAC,CAAC;gBACtC,MAAA,cAAc,CAAC,OAAO,+DAAG,KAAK,CAAC,CAAC;gBAEhC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;aACxC;YAED,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAM,KAAK,GAAG,WAAW,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IACvD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC;QACR,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAE7B,OAAO;YACL,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAChC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n} from '../types/types';\n\nimport {\n ApolloCache,\n DefaultContext,\n mergeOptions,\n OperationVariables,\n} from '../../core';\nimport { equal } from '@wry/equality';\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { ApolloError } from '../../errors';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useMutation<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: MutationHookOptions<TData, TVariables, TContext>,\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = useState<Omit<MutationResult, 'reset'>>({\n called: false,\n loading: false,\n client,\n });\n\n const ref = useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n // TODO: Trying to assign these in a useEffect or useLayoutEffect breaks\n // higher-order components.\n {\n Object.assign(ref.current, { client, options, mutation });\n }\n\n const execute = useCallback((\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const {client, options, mutation} = ref.current;\n const baseOptions = { ...options, mutation };\n if (!ref.current.result.loading && !baseOptions.ignoreResults) {\n setResult(ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n });\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(\n baseOptions,\n executeOptions as any,\n );\n\n return client.mutate(clientOptions).then((response) => {\n const { data, errors } = response;\n const error =\n errors && errors.length > 0\n ? new ApolloError({ graphQLErrors: errors })\n : void 0;\n\n if (\n mutationId === ref.current.mutationId &&\n !clientOptions.ignoreResults\n ) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n ref.current.options?.onCompleted?.(response.data!);\n executeOptions.onCompleted?.(response.data!);\n return response;\n }).catch((error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n if (ref.current.options?.onError || clientOptions.onError) {\n ref.current.options?.onError?.(error);\n executeOptions.onError?.(error);\n // TODO(brian): why are we returning this here???\n return { data: void 0, errors: error };\n }\n\n throw error;\n });\n }, []);\n\n const reset = useCallback(() => {\n setResult({ called: false, loading: false, client });\n }, []);\n\n useEffect(() => {\n ref.current.isMounted = true;\n\n return () => {\n ref.current.isMounted = false;\n };\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
@@ -7,7 +7,7 @@ export declare function useInternalState<TData, TVariables>(client: ApolloClient
7
7
  declare class InternalState<TData, TVariables> {
8
8
  readonly client: ReturnType<typeof useApolloClient>;
9
9
  readonly query: DocumentNode | TypedDocumentNode<TData, TVariables>;
10
- constructor(client: ReturnType<typeof useApolloClient>, query: DocumentNode | TypedDocumentNode<TData, TVariables>);
10
+ constructor(client: ReturnType<typeof useApolloClient>, query: DocumentNode | TypedDocumentNode<TData, TVariables>, previous?: InternalState<TData, TVariables>);
11
11
  forceUpdate(): void;
12
12
  asyncUpdate(): Promise<QueryResult<TData, TVariables>>;
13
13
  private asyncResolveFns;
@@ -17,6 +17,7 @@ declare class InternalState<TData, TVariables> {
17
17
  private queryHookOptions;
18
18
  private watchQueryOptions;
19
19
  private useOptions;
20
+ private getObsQueryOptions;
20
21
  private ssrDisabledResult;
21
22
  private skipStandbyResult;
22
23
  private createWatchQueryOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAYA,OAAO,EAAgB,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGrF,OAAO,EACL,YAAY,EACZ,iBAAiB,EAGjB,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,WAAW,EAEZ,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AASpD,wBAAgB,QAAQ,CACtB,KAAK,GA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"../../core/index.js";
10
10
  import { DocumentType, verifyDocumentType } from "../parser/index.js";
11
11
  import { useApolloClient } from "./useApolloClient.js";
12
- import { canUseWeakMap, canUseWeakSet, isNonEmptyArray, maybeDeepFreeze } from "../../utilities/index.js";
12
+ import { canUseWeakMap, canUseWeakSet, compact, isNonEmptyArray, maybeDeepFreeze } from "../../utilities/index.js";
13
13
  var hasOwnProperty = Object.prototype.hasOwnProperty;
14
14
  export function useQuery(query, options) {
15
15
  if (options === void 0) { options = Object.create(null); }
@@ -20,7 +20,7 @@ export function useInternalState(client, query) {
20
20
  if (!stateRef.current ||
21
21
  client !== stateRef.current.client ||
22
22
  query !== stateRef.current.query) {
23
- stateRef.current = new InternalState(client, query);
23
+ stateRef.current = new InternalState(client, query, stateRef.current);
24
24
  }
25
25
  var state = stateRef.current;
26
26
  var _a = useState(0), _tick = _a[0], setTick = _a[1];
@@ -30,7 +30,7 @@ export function useInternalState(client, query) {
30
30
  return state;
31
31
  }
32
32
  var InternalState = (function () {
33
- function InternalState(client, query) {
33
+ function InternalState(client, query, previous) {
34
34
  this.client = client;
35
35
  this.query = query;
36
36
  this.asyncResolveFns = new Set();
@@ -49,6 +49,11 @@ var InternalState = (function () {
49
49
  });
50
50
  this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
51
51
  verifyDocumentType(query, DocumentType.Query);
52
+ var previousResult = previous && previous.result;
53
+ var previousData = previousResult && previousResult.data;
54
+ if (previousData) {
55
+ this.previousData = previousData;
56
+ }
52
57
  }
53
58
  InternalState.prototype.forceUpdate = function () {
54
59
  __DEV__ && invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
@@ -130,7 +135,7 @@ var InternalState = (function () {
130
135
  this.watchQueryOptions = watchQueryOptions;
131
136
  if (currentWatchQueryOptions && this.observable) {
132
137
  this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
133
- this.observable.reobserve(watchQueryOptions);
138
+ this.observable.reobserve(this.getObsQueryOptions());
134
139
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
135
140
  this.result = void 0;
136
141
  }
@@ -151,6 +156,17 @@ var InternalState = (function () {
151
156
  this.result = void 0;
152
157
  }
153
158
  };
159
+ InternalState.prototype.getObsQueryOptions = function () {
160
+ var toMerge = [];
161
+ var globalDefaults = this.client.defaultOptions.watchQuery;
162
+ if (globalDefaults)
163
+ toMerge.push(globalDefaults);
164
+ if (this.queryHookOptions.defaultOptions) {
165
+ toMerge.push(this.queryHookOptions.defaultOptions);
166
+ }
167
+ toMerge.push(compact(this.observable && this.observable.options, this.watchQueryOptions));
168
+ return toMerge.reduce(mergeOptions);
169
+ };
154
170
  InternalState.prototype.createWatchQueryOptions = function (_a) {
155
171
  var _b;
156
172
  if (_a === void 0) { _a = {}; }
@@ -191,7 +207,7 @@ var InternalState = (function () {
191
207
  this.renderPromises
192
208
  && this.renderPromises.getSSRObservable(this.watchQueryOptions)
193
209
  || this.observable
194
- || this.client.watchQuery(mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
210
+ || this.client.watchQuery(this.getObsQueryOptions());
195
211
  this.obsQueryFields = useMemo(function () { return ({
196
212
  refetch: obsQuery.refetch.bind(obsQuery),
197
213
  reobserve: obsQuery.reobserve.bind(obsQuery),