@apollo/client 3.8.0-alpha.8 → 3.8.0-alpha.9

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 (41) hide show
  1. package/apollo-client.cjs +44 -17
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +14 -3
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +14 -3
  7. package/cache/core/types/DataProxy.d.ts +3 -2
  8. package/cache/core/types/DataProxy.d.ts.map +1 -1
  9. package/cache/core/types/DataProxy.js.map +1 -1
  10. package/cache/inmemory/policies.d.ts.map +1 -1
  11. package/cache/inmemory/policies.js +14 -3
  12. package/cache/inmemory/policies.js.map +1 -1
  13. package/core/ApolloClient.d.ts +3 -3
  14. package/core/ApolloClient.d.ts.map +1 -1
  15. package/core/ApolloClient.js +10 -4
  16. package/core/ApolloClient.js.map +1 -1
  17. package/core/core.cjs +11 -5
  18. package/core/core.cjs.map +1 -1
  19. package/core/core.cjs.native.js +11 -5
  20. package/invariantErrorCodes.js +1 -1
  21. package/package.json +10 -11
  22. package/react/hooks/hooks.cjs +12 -6
  23. package/react/hooks/hooks.cjs.map +1 -1
  24. package/react/hooks/hooks.cjs.native.js +12 -6
  25. package/react/hooks/useMutation.d.ts.map +1 -1
  26. package/react/hooks/useMutation.js +2 -1
  27. package/react/hooks/useMutation.js.map +1 -1
  28. package/react/hooks/useQuery.d.ts.map +1 -1
  29. package/react/hooks/useQuery.js +1 -1
  30. package/react/hooks/useQuery.js.map +1 -1
  31. package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
  32. package/react/hooks/useSuspenseQuery.js +9 -4
  33. package/react/hooks/useSuspenseQuery.js.map +1 -1
  34. package/testing/core/itAsync.js.map +1 -1
  35. package/utilities/graphql/getFromAST.d.ts.map +1 -1
  36. package/utilities/graphql/getFromAST.js +7 -3
  37. package/utilities/graphql/getFromAST.js.map +1 -1
  38. package/utilities/utilities.cjs +7 -3
  39. package/utilities/utilities.cjs.map +1 -1
  40. package/utilities/utilities.cjs.native.js +7 -3
  41. package/version.js +1 -1
package/apollo-client.cjs CHANGED
@@ -398,17 +398,21 @@ function checkDocument(doc) {
398
398
  }
399
399
  function getOperationDefinition(doc) {
400
400
  checkDocument(doc);
401
- return doc.definitions.filter(function (definition) { return definition.kind === 'OperationDefinition'; })[0];
401
+ return doc.definitions.filter(function (definition) {
402
+ return definition.kind === 'OperationDefinition';
403
+ })[0];
402
404
  }
403
405
  function getOperationName(doc) {
404
406
  return (doc.definitions
405
407
  .filter(function (definition) {
406
- return definition.kind === 'OperationDefinition' && definition.name;
408
+ return definition.kind === 'OperationDefinition' && !!definition.name;
407
409
  })
408
410
  .map(function (x) { return x.name.value; })[0] || null);
409
411
  }
410
412
  function getFragmentDefinitions(doc) {
411
- return doc.definitions.filter(function (definition) { return definition.kind === 'FragmentDefinition'; });
413
+ return doc.definitions.filter(function (definition) {
414
+ return definition.kind === 'FragmentDefinition';
415
+ });
412
416
  }
413
417
  function getQueryDefinition(doc) {
414
418
  var queryDef = getOperationDefinition(doc);
@@ -1391,7 +1395,7 @@ var concat = ApolloLink.concat;
1391
1395
 
1392
1396
  var execute = ApolloLink.execute;
1393
1397
 
1394
- var version = '3.8.0-alpha.8';
1398
+ var version = '3.8.0-alpha.9';
1395
1399
 
1396
1400
  function asyncIterator(source) {
1397
1401
  var _a;
@@ -3317,9 +3321,20 @@ var Policies = (function () {
3317
3321
  if (!hasOwn.call(this.typePolicies, typename)) {
3318
3322
  var policy_1 = this.typePolicies[typename] = Object.create(null);
3319
3323
  policy_1.fields = Object.create(null);
3320
- var supertypes = this.supertypeMap.get(typename);
3321
- if (supertypes && supertypes.size) {
3322
- supertypes.forEach(function (supertype) {
3324
+ var supertypes_1 = this.supertypeMap.get(typename);
3325
+ if (!supertypes_1 && this.fuzzySubtypes.size) {
3326
+ supertypes_1 = this.getSupertypeSet(typename, true);
3327
+ this.fuzzySubtypes.forEach(function (regExp, fuzzy) {
3328
+ if (regExp.test(typename)) {
3329
+ var fuzzySupertypes = _this.supertypeMap.get(fuzzy);
3330
+ if (fuzzySupertypes) {
3331
+ fuzzySupertypes.forEach(function (supertype) { return supertypes_1.add(supertype); });
3332
+ }
3333
+ }
3334
+ });
3335
+ }
3336
+ if (supertypes_1 && supertypes_1.size) {
3337
+ supertypes_1.forEach(function (supertype) {
3323
3338
  var _a = _this.getTypePolicy(supertype), fields = _a.fields, rest = tslib.__rest(_a, ["fields"]);
3324
3339
  Object.assign(policy_1, rest);
3325
3340
  Object.assign(policy_1.fields, fields);
@@ -6409,12 +6424,18 @@ var ApolloClient = (function () {
6409
6424
  return this.cache.readFragment(options, optimistic);
6410
6425
  };
6411
6426
  ApolloClient.prototype.writeQuery = function (options) {
6412
- this.cache.writeQuery(options);
6413
- this.queryManager.broadcastQueries();
6427
+ var ref = this.cache.writeQuery(options);
6428
+ if (options.broadcast !== false) {
6429
+ this.queryManager.broadcastQueries();
6430
+ }
6431
+ return ref;
6414
6432
  };
6415
6433
  ApolloClient.prototype.writeFragment = function (options) {
6416
- this.cache.writeFragment(options);
6417
- this.queryManager.broadcastQueries();
6434
+ var ref = this.cache.writeFragment(options);
6435
+ if (options.broadcast !== false) {
6436
+ this.queryManager.broadcastQueries();
6437
+ }
6438
+ return ref;
6418
6439
  };
6419
6440
  ApolloClient.prototype.__actionHookForDevTools = function (cb) {
6420
6441
  this.devToolsHookCb = cb;
@@ -6800,7 +6821,7 @@ var InternalState = (function () {
6800
6821
  }
6801
6822
  };
6802
6823
  var subscription = obsQuery.subscribe(onNext, onError);
6803
- return function () { return subscription.unsubscribe(); };
6824
+ return function () { return setTimeout(function () { return subscription.unsubscribe(); }); };
6804
6825
  }, [
6805
6826
  obsQuery,
6806
6827
  this.renderPromises,
@@ -7067,8 +7088,9 @@ function useMutation(mutation, options) {
7067
7088
  }
7068
7089
  var execute = React.useCallback(function (executeOptions) {
7069
7090
  if (executeOptions === void 0) { executeOptions = {}; }
7070
- var _a = ref.current, client = _a.client, options = _a.options, mutation = _a.mutation;
7091
+ var _a = ref.current, options = _a.options, mutation = _a.mutation;
7071
7092
  var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
7093
+ var client = executeOptions.client || ref.current.client;
7072
7094
  if (!ref.current.result.loading && !baseOptions.ignoreResults && ref.current.isMounted) {
7073
7095
  setResult(ref.current.result = {
7074
7096
  loading: true,
@@ -7481,6 +7503,7 @@ function useIsDeferred(query) {
7481
7503
  function useObservableQueryResult(observable) {
7482
7504
  var resultRef = React.useRef();
7483
7505
  var isMountedRef = React.useRef(false);
7506
+ var subscribeTimeoutRef = React.useRef();
7484
7507
  if (!resultRef.current) {
7485
7508
  resultRef.current = observable.getCurrentResult();
7486
7509
  }
@@ -7491,6 +7514,7 @@ function useObservableQueryResult(observable) {
7491
7514
  };
7492
7515
  }, []);
7493
7516
  return useSyncExternalStore(React.useCallback(function (forceUpdate) {
7517
+ clearTimeout(subscribeTimeoutRef.current);
7494
7518
  function handleUpdate() {
7495
7519
  var previousResult = resultRef.current;
7496
7520
  var result = observable.getCurrentResult();
@@ -7504,12 +7528,15 @@ function useObservableQueryResult(observable) {
7504
7528
  forceUpdate();
7505
7529
  }
7506
7530
  }
7507
- var subscription = observable.subscribe({
7508
- next: handleUpdate,
7509
- error: handleUpdate,
7531
+ var subscription;
7532
+ subscribeTimeoutRef.current = setTimeout(function () {
7533
+ subscription = observable.subscribe({
7534
+ next: handleUpdate,
7535
+ error: handleUpdate,
7536
+ });
7510
7537
  });
7511
7538
  return function () {
7512
- subscription.unsubscribe();
7539
+ subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe();
7513
7540
  };
7514
7541
  }, [observable]), function () { return resultRef.current; }, function () { return resultRef.current; });
7515
7542
  }