@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
@@ -2,15 +2,15 @@ import { Trie } from "@wry/trie";
2
2
  import type { DocumentNode } from "graphql";
3
3
  import { Observable } from "rxjs";
4
4
  import type { ApolloCache, Cache } from "@apollo/client/cache";
5
- import type { ApolloLink, FetchResult } from "@apollo/client/link/core";
5
+ import type { FetchResult } from "@apollo/client/link/core";
6
6
  import type { MaybeMasked } from "@apollo/client/masking";
7
7
  import { DocumentTransform } from "@apollo/client/utilities";
8
- import type { DefaultOptions } from "./ApolloClient.js";
8
+ import type { ApolloClient, DefaultOptions } from "./ApolloClient.js";
9
9
  import type { LocalState } from "./LocalState.js";
10
10
  import { NetworkStatus } from "./networkStatus.js";
11
11
  import { ObservableQuery } from "./ObservableQuery.js";
12
12
  import { QueryInfo } from "./QueryInfo.js";
13
- import type { ApolloQueryResult, DefaultContext, InternalRefetchQueriesInclude, InternalRefetchQueriesMap, InternalRefetchQueriesOptions, MutateResult, MutationUpdaterFunction, OnQueryUpdated, OperationVariables, QueryResult, SubscribeResult, TypedDocumentNode } from "./types.js";
13
+ import type { ApolloQueryResult, ClientAwareness, DefaultContext, InternalRefetchQueriesInclude, InternalRefetchQueriesMap, InternalRefetchQueriesOptions, MutateResult, MutationUpdaterFunction, OnQueryUpdated, OperationVariables, QueryResult, SubscribeResult, TypedDocumentNode } from "./types.js";
14
14
  import type { ErrorPolicy, MutationFetchPolicy, MutationOptions, QueryOptions, SubscriptionOptions, WatchQueryFetchPolicy, WatchQueryOptions } from "./watchQueryOptions.js";
15
15
  interface MutationStoreValue {
16
16
  mutation: DocumentNode;
@@ -41,23 +41,21 @@ interface MaskOperationOptions<TData> {
41
41
  fetchPolicy?: WatchQueryFetchPolicy;
42
42
  }
43
43
  interface QueryManagerOptions {
44
- cache: ApolloCache;
45
- link: ApolloLink;
44
+ client: ApolloClient;
46
45
  defaultOptions: DefaultOptions;
47
46
  documentTransform: DocumentTransform | null | undefined;
48
47
  queryDeduplication: boolean;
49
48
  onBroadcast: undefined | (() => void);
50
49
  ssrMode: boolean;
51
- clientAwareness: Record<string, string>;
50
+ clientAwareness: ClientAwareness;
52
51
  localState: LocalState;
53
52
  assumeImmutableResults: boolean;
54
53
  defaultContext: Partial<DefaultContext> | undefined;
55
54
  dataMasking: boolean;
56
55
  }
57
56
  export declare class QueryManager {
58
- cache: ApolloCache;
59
- link: ApolloLink;
60
57
  defaultOptions: DefaultOptions;
58
+ readonly client: ApolloClient;
61
59
  readonly assumeImmutableResults: boolean;
62
60
  readonly documentTransform: DocumentTransform;
63
61
  readonly ssrMode: boolean;
@@ -84,6 +82,8 @@ export declare class QueryManager {
84
82
  private queries;
85
83
  protected fetchCancelFns: Map<string, (error: any) => any>;
86
84
  constructor(options: QueryManagerOptions);
85
+ get link(): import("@apollo/client/link/core").ApolloLink;
86
+ get cache(): ApolloCache;
87
87
  /**
88
88
  * Call this method to terminate any active query processes, making it safe
89
89
  * to dispose of this QueryManager instance.
@@ -135,7 +135,6 @@ export declare class QueryManager {
135
135
  getObservableQueries(include?: InternalRefetchQueriesInclude): Map<string, ObservableQuery<any, OperationVariables>>;
136
136
  reFetchObservableQueries(includeStandby?: boolean): Promise<QueryResult<any>[]>;
137
137
  startGraphQLSubscription<TData = unknown>(options: SubscriptionOptions): Observable<SubscribeResult<TData>>;
138
- stopQuery(queryId: string): void;
139
138
  removeQuery(queryId: string): void;
140
139
  broadcastQueries(): void;
141
140
  getLocalState(): LocalState;
@@ -151,9 +150,8 @@ export declare class QueryManager {
151
150
  maskFragment<TData = unknown>(options: MaskFragmentOptions<TData>): TData;
152
151
  private fetchQueryByPolicy;
153
152
  getOrCreateQuery(queryId: string): QueryInfo;
154
- private prepareContext;
155
153
  }
156
- export interface ObservableAndInfo<TData> {
154
+ interface ObservableAndInfo<TData> {
157
155
  fromLink: boolean;
158
156
  observable: Observable<ApolloQueryResult<TData>>;
159
157
  }
@@ -20,9 +20,8 @@ import { QueryInfo, shouldWriteResult, } from "./QueryInfo.js";
20
20
  const { hasOwnProperty } = Object.prototype;
21
21
  const IGNORE = {};
22
22
  export class QueryManager {
23
- cache;
24
- link;
25
23
  defaultOptions;
24
+ client;
26
25
  assumeImmutableResults;
27
26
  documentTransform;
28
27
  ssrMode;
@@ -56,8 +55,7 @@ export class QueryManager {
56
55
  const defaultDocumentTransform = new DocumentTransform((document) => this.cache.transformDocument(document),
57
56
  // Allow the apollo cache to manage its own transform caches
58
57
  { cache: false });
59
- this.cache = options.cache;
60
- this.link = options.link;
58
+ this.client = options.client;
61
59
  this.defaultOptions = options.defaultOptions;
62
60
  this.queryDeduplication = options.queryDeduplication;
63
61
  this.clientAwareness = options.clientAwareness;
@@ -81,6 +79,12 @@ export class QueryManager {
81
79
  this.mutationStore = {};
82
80
  }
83
81
  }
82
+ get link() {
83
+ return this.client.link;
84
+ }
85
+ get cache() {
86
+ return this.client.cache;
87
+ }
84
88
  /**
85
89
  * Call this method to terminate any active query processes, making it safe
86
90
  * to dispose of this QueryManager instance.
@@ -496,7 +500,7 @@ export class QueryManager {
496
500
  id: queryId,
497
501
  }),
498
502
  }))
499
- .finally(() => this.stopQuery(queryId));
503
+ .finally(() => this.removeQuery(queryId));
500
504
  }
501
505
  queryIdCounter = 1;
502
506
  generateQueryId() {
@@ -690,10 +694,6 @@ export class QueryManager {
690
694
  }
691
695
  return makeObservable(variables);
692
696
  }
693
- stopQuery(queryId) {
694
- this.removeQuery(queryId);
695
- this.broadcastQueries();
696
- }
697
697
  removeQuery(queryId) {
698
698
  // teardown all links
699
699
  // Both `QueryManager.fetchRequest` and `QueryManager.query` create separate promises
@@ -723,16 +723,25 @@ export class QueryManager {
723
723
  this.queryDeduplication) {
724
724
  let observable;
725
725
  const { serverQuery, clientQuery } = this.getDocumentInfo(query);
726
+ const prepareContext = (context = {}) => {
727
+ const newContext = this.localState.prepareContext(context);
728
+ return {
729
+ ...this.defaultContext,
730
+ ...newContext,
731
+ queryDeduplication: deduplication,
732
+ clientAwareness: this.clientAwareness,
733
+ };
734
+ };
735
+ const executeContext = {
736
+ client: this.client,
737
+ };
726
738
  if (serverQuery) {
727
739
  const { inFlightLinkObservables, link } = this;
728
740
  const operation = {
729
741
  query: serverQuery,
730
742
  variables,
731
743
  operationName: getOperationName(serverQuery) || void 0,
732
- context: this.prepareContext({
733
- ...context,
734
- forceFetch: !deduplication,
735
- }),
744
+ context: prepareContext(context),
736
745
  extensions,
737
746
  };
738
747
  context = operation.context;
@@ -742,7 +751,7 @@ export class QueryManager {
742
751
  const entry = inFlightLinkObservables.lookup(printedServerQuery, varJson);
743
752
  observable = entry.observable;
744
753
  if (!observable) {
745
- observable = entry.observable = execute(link, operation).pipe(onAnyEvent((event) => {
754
+ observable = entry.observable = execute(link, operation, executeContext).pipe(onAnyEvent((event) => {
746
755
  if ((event.type !== "next" ||
747
756
  !("hasNext" in event.value) ||
748
757
  !event.value.hasNext) &&
@@ -754,12 +763,12 @@ export class QueryManager {
754
763
  }
755
764
  }
756
765
  else {
757
- observable = execute(link, operation);
766
+ observable = execute(link, operation, executeContext);
758
767
  }
759
768
  }
760
769
  else {
761
770
  observable = of({ data: {} });
762
- context = this.prepareContext(context);
771
+ context = prepareContext(context);
763
772
  }
764
773
  if (clientQuery) {
765
774
  observable = observable.pipe(mergeMap((result) => {
@@ -1201,14 +1210,6 @@ export class QueryManager {
1201
1210
  }
1202
1211
  return this.queries.get(queryId);
1203
1212
  }
1204
- prepareContext(context = {}) {
1205
- const newContext = this.localState.prepareContext(context);
1206
- return {
1207
- ...this.defaultContext,
1208
- ...newContext,
1209
- clientAwareness: this.clientAwareness,
1210
- };
1211
- }
1212
1213
  }
1213
1214
  function validateDidEmitValue() {
1214
1215
  let didEmitValue = false;