@apollo/client 4.0.0-alpha.10 → 4.0.0-alpha.11

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 (136) hide show
  1. package/.changeset/afraid-grapes-call.md +5 -0
  2. package/.changeset/gentle-waves-cough.md +5 -0
  3. package/.changeset/lucky-sheep-explain.md +34 -0
  4. package/.changeset/orange-suits-laugh.md +5 -0
  5. package/.changeset/perfect-ducks-reflect.md +12 -0
  6. package/.changeset/pre.json +7 -0
  7. package/.changeset/seven-schools-carry.md +5 -0
  8. package/.changeset/small-poems-rest.md +5 -0
  9. package/CHANGELOG.md +59 -0
  10. package/__cjs/core/ApolloClient.cjs +3 -4
  11. package/__cjs/core/ApolloClient.cjs.map +1 -1
  12. package/__cjs/core/ApolloClient.d.cts +2 -2
  13. package/__cjs/core/LocalState.cjs +0 -1
  14. package/__cjs/core/LocalState.cjs.map +1 -1
  15. package/__cjs/core/LocalState.d.cts +0 -1
  16. package/__cjs/core/ObservableQuery.cjs +6 -6
  17. package/__cjs/core/ObservableQuery.cjs.map +1 -1
  18. package/__cjs/core/QueryManager.cjs +25 -24
  19. package/__cjs/core/QueryManager.cjs.map +1 -1
  20. package/__cjs/core/QueryManager.d.cts +9 -11
  21. package/__cjs/core/index.cjs.map +1 -1
  22. package/__cjs/core/index.d.cts +3 -3
  23. package/__cjs/core/types.d.cts +5 -0
  24. package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
  25. package/__cjs/link/batch-http/batchHttpLink.d.cts +3 -2
  26. package/__cjs/link/context/index.cjs.map +1 -1
  27. package/__cjs/link/context/index.d.cts +2 -3
  28. package/__cjs/link/core/ApolloLink.cjs +2 -2
  29. package/__cjs/link/core/ApolloLink.cjs.map +1 -1
  30. package/__cjs/link/core/ApolloLink.d.cts +2 -2
  31. package/__cjs/link/core/index.cjs.map +1 -1
  32. package/__cjs/link/core/index.d.cts +1 -1
  33. package/__cjs/link/core/types.d.cts +15 -4
  34. package/__cjs/link/http/HttpLink.cjs.map +1 -1
  35. package/__cjs/link/http/HttpLink.d.cts +128 -3
  36. package/__cjs/link/http/createHttpLink.cjs.map +1 -1
  37. package/__cjs/link/http/createHttpLink.d.cts +2 -2
  38. package/__cjs/link/http/index.cjs.map +1 -1
  39. package/__cjs/link/http/index.d.cts +0 -1
  40. package/__cjs/link/http/rewriteURIForGET.cjs.map +1 -1
  41. package/__cjs/link/http/rewriteURIForGET.d.cts +2 -2
  42. package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
  43. package/__cjs/link/http/selectHttpOptionsAndBody.d.cts +7 -82
  44. package/__cjs/link/utils/createOperation.cjs +5 -1
  45. package/__cjs/link/utils/createOperation.cjs.map +1 -1
  46. package/__cjs/link/utils/createOperation.d.cts +2 -2
  47. package/__cjs/react/hooks/useMutation.cjs.map +1 -1
  48. package/__cjs/react/hooks/useMutation.d.cts +41 -8
  49. package/__cjs/react/index.cjs +3 -1
  50. package/__cjs/react/index.cjs.map +1 -1
  51. package/__cjs/react/index.d.cts +1 -0
  52. package/__cjs/react/types/deprecated.d.cts +3 -3
  53. package/__cjs/testing/internal/index.cjs +4 -1
  54. package/__cjs/testing/internal/index.cjs.map +1 -1
  55. package/__cjs/testing/internal/index.d.cts +1 -0
  56. package/__cjs/testing/internal/link.cjs +16 -0
  57. package/__cjs/testing/internal/link.cjs.map +1 -0
  58. package/__cjs/testing/internal/link.d.cts +5 -0
  59. package/__cjs/testing/matchers/isSameClient.cjs +19 -0
  60. package/__cjs/testing/matchers/isSameClient.cjs.map +1 -0
  61. package/__cjs/testing/matchers/isSameClient.d.cts +3 -0
  62. package/__cjs/testing/matchers/isSameObservableQuery.cjs +19 -0
  63. package/__cjs/testing/matchers/isSameObservableQuery.cjs.map +1 -0
  64. package/__cjs/testing/matchers/isSameObservableQuery.d.cts +3 -0
  65. package/__cjs/testing/matchers/toStrictEqualTyped.cjs +9 -3
  66. package/__cjs/testing/matchers/toStrictEqualTyped.cjs.map +1 -1
  67. package/__cjs/testing/matchers/toStrictEqualTyped.d.cts +6 -1
  68. package/__cjs/testing/matchers/utils/getSerializableProperties.cjs +3 -2
  69. package/__cjs/testing/matchers/utils/getSerializableProperties.cjs.map +1 -1
  70. package/__cjs/testing/matchers/utils/getSerializableProperties.d.cts +3 -1
  71. package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
  72. package/__cjs/version.cjs +1 -1
  73. package/core/ApolloClient.d.ts +2 -2
  74. package/core/ApolloClient.js +3 -4
  75. package/core/ApolloClient.js.map +1 -1
  76. package/core/LocalState.d.ts +0 -1
  77. package/core/LocalState.js +0 -1
  78. package/core/LocalState.js.map +1 -1
  79. package/core/ObservableQuery.js +6 -6
  80. package/core/ObservableQuery.js.map +1 -1
  81. package/core/QueryManager.d.ts +9 -11
  82. package/core/QueryManager.js +25 -24
  83. package/core/QueryManager.js.map +1 -1
  84. package/core/index.d.ts +3 -3
  85. package/core/index.js.map +1 -1
  86. package/core/types.d.ts +5 -0
  87. package/link/batch-http/batchHttpLink.d.ts +3 -2
  88. package/link/batch-http/batchHttpLink.js.map +1 -1
  89. package/link/context/index.d.ts +2 -3
  90. package/link/context/index.js.map +1 -1
  91. package/link/core/ApolloLink.d.ts +2 -2
  92. package/link/core/ApolloLink.js +2 -2
  93. package/link/core/ApolloLink.js.map +1 -1
  94. package/link/core/index.d.ts +1 -1
  95. package/link/core/index.js.map +1 -1
  96. package/link/core/types.d.ts +15 -4
  97. package/link/http/HttpLink.d.ts +128 -3
  98. package/link/http/HttpLink.js.map +1 -1
  99. package/link/http/createHttpLink.d.ts +2 -2
  100. package/link/http/createHttpLink.js.map +1 -1
  101. package/link/http/index.d.ts +0 -1
  102. package/link/http/index.js.map +1 -1
  103. package/link/http/rewriteURIForGET.d.ts +2 -2
  104. package/link/http/rewriteURIForGET.js.map +1 -1
  105. package/link/http/selectHttpOptionsAndBody.d.ts +7 -82
  106. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  107. package/link/utils/createOperation.d.ts +2 -2
  108. package/link/utils/createOperation.js +5 -1
  109. package/link/utils/createOperation.js.map +1 -1
  110. package/package.json +1 -1
  111. package/react/hooks/useMutation.d.ts +41 -8
  112. package/react/hooks/useMutation.js.map +1 -1
  113. package/react/index.d.ts +1 -0
  114. package/react/index.js +1 -0
  115. package/react/index.js.map +1 -1
  116. package/react/types/deprecated.d.ts +3 -3
  117. package/testing/internal/index.d.ts +1 -0
  118. package/testing/internal/index.js +1 -0
  119. package/testing/internal/index.js.map +1 -1
  120. package/testing/internal/link.d.ts +5 -0
  121. package/testing/internal/link.js +12 -0
  122. package/testing/internal/link.js.map +1 -0
  123. package/testing/matchers/isSameClient.d.ts +3 -0
  124. package/testing/matchers/isSameClient.js +15 -0
  125. package/testing/matchers/isSameClient.js.map +1 -0
  126. package/testing/matchers/isSameObservableQuery.d.ts +3 -0
  127. package/testing/matchers/isSameObservableQuery.js +15 -0
  128. package/testing/matchers/isSameObservableQuery.js.map +1 -0
  129. package/testing/matchers/toStrictEqualTyped.d.ts +6 -1
  130. package/testing/matchers/toStrictEqualTyped.js +9 -3
  131. package/testing/matchers/toStrictEqualTyped.js.map +1 -1
  132. package/testing/matchers/utils/getSerializableProperties.d.ts +3 -1
  133. package/testing/matchers/utils/getSerializableProperties.js +3 -2
  134. package/testing/matchers/utils/getSerializableProperties.js.map +1 -1
  135. package/utilities/subscriptions/relay/index.js.map +1 -1
  136. package/version.js +1 -1
@@ -27,9 +27,8 @@ const QueryInfo_js_1 = require("./QueryInfo.cjs");
27
27
  const { hasOwnProperty } = Object.prototype;
28
28
  const IGNORE = {};
29
29
  class QueryManager {
30
- cache;
31
- link;
32
30
  defaultOptions;
31
+ client;
33
32
  assumeImmutableResults;
34
33
  documentTransform;
35
34
  ssrMode;
@@ -63,8 +62,7 @@ class QueryManager {
63
62
  const defaultDocumentTransform = new utilities_4.DocumentTransform((document) => this.cache.transformDocument(document),
64
63
  // Allow the apollo cache to manage its own transform caches
65
64
  { cache: false });
66
- this.cache = options.cache;
67
- this.link = options.link;
65
+ this.client = options.client;
68
66
  this.defaultOptions = options.defaultOptions;
69
67
  this.queryDeduplication = options.queryDeduplication;
70
68
  this.clientAwareness = options.clientAwareness;
@@ -88,6 +86,12 @@ class QueryManager {
88
86
  this.mutationStore = {};
89
87
  }
90
88
  }
89
+ get link() {
90
+ return this.client.link;
91
+ }
92
+ get cache() {
93
+ return this.client.cache;
94
+ }
91
95
  /**
92
96
  * Call this method to terminate any active query processes, making it safe
93
97
  * to dispose of this QueryManager instance.
@@ -503,7 +507,7 @@ class QueryManager {
503
507
  id: queryId,
504
508
  }),
505
509
  }))
506
- .finally(() => this.stopQuery(queryId));
510
+ .finally(() => this.removeQuery(queryId));
507
511
  }
508
512
  queryIdCounter = 1;
509
513
  generateQueryId() {
@@ -697,10 +701,6 @@ class QueryManager {
697
701
  }
698
702
  return makeObservable(variables);
699
703
  }
700
- stopQuery(queryId) {
701
- this.removeQuery(queryId);
702
- this.broadcastQueries();
703
- }
704
704
  removeQuery(queryId) {
705
705
  // teardown all links
706
706
  // Both `QueryManager.fetchRequest` and `QueryManager.query` create separate promises
@@ -730,16 +730,25 @@ class QueryManager {
730
730
  this.queryDeduplication) {
731
731
  let observable;
732
732
  const { serverQuery, clientQuery } = this.getDocumentInfo(query);
733
+ const prepareContext = (context = {}) => {
734
+ const newContext = this.localState.prepareContext(context);
735
+ return {
736
+ ...this.defaultContext,
737
+ ...newContext,
738
+ queryDeduplication: deduplication,
739
+ clientAwareness: this.clientAwareness,
740
+ };
741
+ };
742
+ const executeContext = {
743
+ client: this.client,
744
+ };
733
745
  if (serverQuery) {
734
746
  const { inFlightLinkObservables, link } = this;
735
747
  const operation = {
736
748
  query: serverQuery,
737
749
  variables,
738
750
  operationName: (0, utilities_4.getOperationName)(serverQuery) || void 0,
739
- context: this.prepareContext({
740
- ...context,
741
- forceFetch: !deduplication,
742
- }),
751
+ context: prepareContext(context),
743
752
  extensions,
744
753
  };
745
754
  context = operation.context;
@@ -749,7 +758,7 @@ class QueryManager {
749
758
  const entry = inFlightLinkObservables.lookup(printedServerQuery, varJson);
750
759
  observable = entry.observable;
751
760
  if (!observable) {
752
- observable = entry.observable = (0, core_1.execute)(link, operation).pipe((0, internal_1.onAnyEvent)((event) => {
761
+ observable = entry.observable = (0, core_1.execute)(link, operation, executeContext).pipe((0, internal_1.onAnyEvent)((event) => {
753
762
  if ((event.type !== "next" ||
754
763
  !("hasNext" in event.value) ||
755
764
  !event.value.hasNext) &&
@@ -761,12 +770,12 @@ class QueryManager {
761
770
  }
762
771
  }
763
772
  else {
764
- observable = (0, core_1.execute)(link, operation);
773
+ observable = (0, core_1.execute)(link, operation, executeContext);
765
774
  }
766
775
  }
767
776
  else {
768
777
  observable = (0, rxjs_1.of)({ data: {} });
769
- context = this.prepareContext(context);
778
+ context = prepareContext(context);
770
779
  }
771
780
  if (clientQuery) {
772
781
  observable = observable.pipe((0, rxjs_1.mergeMap)((result) => {
@@ -1208,14 +1217,6 @@ class QueryManager {
1208
1217
  }
1209
1218
  return this.queries.get(queryId);
1210
1219
  }
1211
- prepareContext(context = {}) {
1212
- const newContext = this.localState.prepareContext(context);
1213
- return {
1214
- ...this.defaultContext,
1215
- ...newContext,
1216
- clientAwareness: this.clientAwareness,
1217
- };
1218
- }
1219
1220
  }
1220
1221
  exports.QueryManager = QueryManager;
1221
1222
  function validateDidEmitValue() {