@apollo/client 4.2.3 → 4.3.0-alpha.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 4.3.0-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#13268](https://github.com/apollographql/apollo-client/pull/13268) [`419e2b5`](https://github.com/apollographql/apollo-client/commit/419e2b5bfe573d1eb4c3a0ff7aa9084e6aaa2f37) Thanks [@DaleSeo](https://github.com/DaleSeo)! - Align the remaining cache generic constraints with `Cache.Implementation`. The deprecated React mutation types (`MutationHookOptions`, `MutationFunctionOptions`, `MutationTuple`) and the internal `InternalRefetchQueriesOptions` and `QueryInfo` types still constrained their cache type parameter to `ApolloCache`, so they now match the rest of the overridable cache API.
8
+
9
+ ## 4.3.0-alpha.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#13250](https://github.com/apollographql/apollo-client/pull/13250) [`bad7035`](https://github.com/apollographql/apollo-client/commit/bad7035565e15c18800080d9e0abf1d89b3d82fa) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Add the ability to define the cache type for the client. `client.cache` currently returns `ApolloCache` as the cache type regardless of what cache you've provided to `ApolloClient`.
14
+
15
+ Declare the cache type using the `cache` property in the `TypeOverrides` interface to set the cache implementation used for the client.
16
+
17
+ ```ts
18
+ // apollo.d.ts
19
+ import type { InMemoryCache } from "@apollo/client";
20
+
21
+ declare module "@apollo/client" {
22
+ export interface TypeOverrides {
23
+ cache: InMemoryCache;
24
+ }
25
+ }
26
+ ```
27
+
28
+ Now anywhere `cache` is accessible, the type is the declared cache type:
29
+
30
+ ```ts
31
+ client.cache;
32
+ // ^? InMemoryCache
33
+
34
+ client.mutate({
35
+ update: (cache) => {
36
+ // ^? InMemoryCache
37
+ },
38
+ });
39
+ ```
40
+
41
+ > [!NOTE]
42
+ > Setting a cache type enforces that cache type in the `cache` option for the `ApolloClient` constructor.
43
+
3
44
  ## 4.2.3
4
45
 
5
46
  ### Patch Changes
@@ -1,10 +1,13 @@
1
- import type { DataValue, DocumentNode, OperationVariables, TypedDocumentNode } from "@apollo/client";
1
+ import type { DataValue, DocumentNode, OperationVariables, TypedDocumentNode, TypeOverrides } from "@apollo/client";
2
2
  import type { Unmasked } from "@apollo/client/masking";
3
3
  import type { ExtensionsWithStreamInfo } from "@apollo/client/utilities/internal";
4
4
  import type { ApolloCache } from "../cache.cjs";
5
5
  import type { AllFieldsModifier, MissingFieldError, Modifiers } from "./common.cjs";
6
6
  export declare namespace Cache {
7
7
  type WatchCallback<TData = unknown> = (diff: Cache.DiffResult<TData>, lastDiff?: Cache.DiffResult<TData>) => void;
8
+ type Implementation = TypeOverrides extends {
9
+ cache: infer TCache;
10
+ } ? TCache extends ApolloCache ? TCache : "The cache type declared in TypeOverrides does not extend `ApolloCache` and cannot be used with Apollo Client. See https://www.apollographql.com/docs/react/data/typescript#declaring-the-cache-type." : ApolloCache;
8
11
  interface ReadOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
9
12
  /**
10
13
  * The GraphQL query shape to be used constructed using the `gql` template
@@ -80,7 +83,7 @@ export declare namespace Cache {
80
83
  optimistic?: boolean;
81
84
  broadcast?: boolean;
82
85
  }
83
- interface BatchOptions<TCache extends ApolloCache, TUpdateResult = void> {
86
+ interface BatchOptions<TCache extends Cache.Implementation, TUpdateResult = void> {
84
87
  /**
85
88
  * A function that performs cache operations. Receives the cache instance as its argument.
86
89
  *