@apollo/client 3.9.0-alpha.5 → 3.9.0-beta.0

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 (154) hide show
  1. package/.changeset/dirty-tigers-matter.md +13 -0
  2. package/.changeset/mighty-coats-check.md +47 -0
  3. package/.changeset/pre.json +9 -1
  4. package/.changeset/rare-snakes-melt.md +24 -0
  5. package/.changeset/swift-zoos-collect.md +19 -0
  6. package/.changeset/thick-tips-cry.md +9 -0
  7. package/.changeset/tough-timers-begin.md +8 -0
  8. package/.changeset/unlucky-rats-decide.md +5 -0
  9. package/.changeset/wet-forks-rhyme.md +5 -0
  10. package/CHANGELOG.md +118 -4
  11. package/apollo-client.cjs +329 -82
  12. package/apollo-client.cjs.map +1 -1
  13. package/apollo-client.min.cjs +1 -1
  14. package/cache/cache.cjs +78 -6
  15. package/cache/cache.cjs.map +1 -1
  16. package/cache/cache.cjs.native.js +78 -6
  17. package/cache/core/cache.d.ts +9 -0
  18. package/cache/core/cache.js +11 -2
  19. package/cache/core/cache.js.map +1 -1
  20. package/cache/core/types/Cache.d.ts +7 -0
  21. package/cache/core/types/Cache.js.map +1 -1
  22. package/cache/core/types/DataProxy.d.ts +12 -0
  23. package/cache/core/types/DataProxy.js.map +1 -1
  24. package/cache/core/types/common.d.ts +4 -0
  25. package/cache/core/types/common.js.map +1 -1
  26. package/cache/inmemory/fragmentRegistry.js +19 -3
  27. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  28. package/cache/inmemory/inMemoryCache.d.ts +9 -0
  29. package/cache/inmemory/inMemoryCache.js +8 -2
  30. package/cache/inmemory/inMemoryCache.js.map +1 -1
  31. package/cache/inmemory/readFromStore.js +7 -3
  32. package/cache/inmemory/readFromStore.js.map +1 -1
  33. package/cache/inmemory/types.d.ts +18 -0
  34. package/cache/inmemory/types.js.map +1 -1
  35. package/core/ApolloClient.d.ts +9 -0
  36. package/core/ApolloClient.js +4 -0
  37. package/core/ApolloClient.js.map +1 -1
  38. package/core/ObservableQuery.d.ts +2 -0
  39. package/core/ObservableQuery.js +7 -1
  40. package/core/ObservableQuery.js.map +1 -1
  41. package/core/QueryInfo.d.ts +1 -0
  42. package/core/QueryInfo.js +4 -0
  43. package/core/QueryInfo.js.map +1 -1
  44. package/core/QueryManager.d.ts +1 -1
  45. package/core/QueryManager.js +15 -10
  46. package/core/QueryManager.js.map +1 -1
  47. package/core/core.cjs +99 -12
  48. package/core/core.cjs.map +1 -1
  49. package/core/core.cjs.native.js +99 -12
  50. package/core/watchQueryOptions.d.ts +20 -1
  51. package/core/watchQueryOptions.js.map +1 -1
  52. package/dev/dev.cjs +1 -1
  53. package/dev/dev.cjs.map +1 -1
  54. package/dev/dev.cjs.native.js +1 -1
  55. package/link/core/ApolloLink.d.ts +15 -0
  56. package/link/core/ApolloLink.js +8 -4
  57. package/link/core/ApolloLink.js.map +1 -1
  58. package/link/core/core.cjs +8 -4
  59. package/link/core/core.cjs.map +1 -1
  60. package/link/core/core.cjs.native.js +8 -4
  61. package/link/persisted-queries/index.d.ts +11 -1
  62. package/link/persisted-queries/index.js +28 -3
  63. package/link/persisted-queries/index.js.map +1 -1
  64. package/link/persisted-queries/persisted-queries.cjs +26 -3
  65. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  66. package/link/persisted-queries/persisted-queries.cjs.native.js +26 -3
  67. package/link/remove-typename/remove-typename.cjs +18 -2
  68. package/link/remove-typename/remove-typename.cjs.map +1 -1
  69. package/link/remove-typename/remove-typename.cjs.native.js +18 -2
  70. package/link/remove-typename/removeTypenameFromVariables.d.ts +9 -1
  71. package/link/remove-typename/removeTypenameFromVariables.js +19 -3
  72. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  73. package/package.json +21 -21
  74. package/react/cache/QueryReference.d.ts +11 -5
  75. package/react/cache/QueryReference.js +91 -55
  76. package/react/cache/QueryReference.js.map +1 -1
  77. package/react/hooks/hooks.cjs +112 -52
  78. package/react/hooks/hooks.cjs.map +1 -1
  79. package/react/hooks/hooks.cjs.native.js +112 -52
  80. package/react/hooks/index.d.ts +2 -0
  81. package/react/hooks/index.js +1 -0
  82. package/react/hooks/index.js.map +1 -1
  83. package/react/hooks/useBackgroundQuery.d.ts +12 -9
  84. package/react/hooks/useBackgroundQuery.js +1 -1
  85. package/react/hooks/useBackgroundQuery.js.map +1 -1
  86. package/react/hooks/useLoadableQuery.d.ts +1 -1
  87. package/react/hooks/useLoadableQuery.js +1 -1
  88. package/react/hooks/useLoadableQuery.js.map +1 -1
  89. package/react/hooks/useQueryRefHandlers.d.ts +35 -0
  90. package/react/hooks/useQueryRefHandlers.js +48 -0
  91. package/react/hooks/useQueryRefHandlers.js.map +1 -0
  92. package/react/hooks/useReadQuery.js +8 -2
  93. package/react/hooks/useReadQuery.js.map +1 -1
  94. package/react/index.d.ts +2 -0
  95. package/react/index.js +1 -0
  96. package/react/index.js.map +1 -1
  97. package/react/parser/index.js +6 -3
  98. package/react/parser/index.js.map +1 -1
  99. package/react/parser/parser.cjs +11 -3
  100. package/react/parser/parser.cjs.map +1 -1
  101. package/react/parser/parser.cjs.native.js +11 -3
  102. package/react/query-preloader/createQueryPreloader.d.ts +253 -0
  103. package/react/query-preloader/createQueryPreloader.js +29 -0
  104. package/react/query-preloader/createQueryPreloader.js.map +1 -0
  105. package/react/react.cjs +248 -1
  106. package/react/react.cjs.map +1 -1
  107. package/react/react.cjs.native.js +248 -1
  108. package/react/types/types.d.ts +6 -0
  109. package/react/types/types.js.map +1 -1
  110. package/testing/internal/index.d.ts +4 -0
  111. package/testing/internal/index.js +2 -0
  112. package/testing/internal/index.js.map +1 -1
  113. package/testing/internal/renderHelpers.d.ts +12 -0
  114. package/testing/internal/renderHelpers.js +22 -0
  115. package/testing/internal/renderHelpers.js.map +1 -0
  116. package/testing/internal/scenarios/index.d.ts +41 -0
  117. package/testing/internal/scenarios/index.js +46 -0
  118. package/testing/internal/scenarios/index.js.map +1 -0
  119. package/testing/matchers/index.js +2 -0
  120. package/testing/matchers/index.js.map +1 -1
  121. package/testing/matchers/toBeDisposed.d.ts +3 -0
  122. package/testing/matchers/toBeDisposed.js +26 -0
  123. package/testing/matchers/toBeDisposed.js.map +1 -0
  124. package/utilities/caching/caches.d.ts +34 -0
  125. package/utilities/caching/caches.js +64 -0
  126. package/utilities/caching/caches.js.map +1 -0
  127. package/utilities/caching/getMemoryInternals.d.ts +76 -0
  128. package/utilities/caching/getMemoryInternals.js +112 -0
  129. package/utilities/caching/getMemoryInternals.js.map +1 -0
  130. package/utilities/caching/index.d.ts +4 -0
  131. package/utilities/caching/index.js +3 -0
  132. package/utilities/caching/index.js.map +1 -0
  133. package/utilities/caching/sizes.d.ts +261 -0
  134. package/utilities/caching/sizes.js +27 -0
  135. package/utilities/caching/sizes.js.map +1 -0
  136. package/utilities/common/canUse.js +1 -1
  137. package/utilities/common/canUse.js.map +1 -1
  138. package/utilities/common/canonicalStringify.js +8 -2
  139. package/utilities/common/canonicalStringify.js.map +1 -1
  140. package/utilities/globals/globals.cjs +1 -1
  141. package/utilities/globals/globals.cjs.map +1 -1
  142. package/utilities/globals/globals.cjs.native.js +1 -1
  143. package/utilities/graphql/DocumentTransform.d.ts +14 -1
  144. package/utilities/graphql/DocumentTransform.js +9 -5
  145. package/utilities/graphql/DocumentTransform.js.map +1 -1
  146. package/utilities/graphql/print.js +6 -2
  147. package/utilities/graphql/print.js.map +1 -1
  148. package/utilities/index.d.ts +2 -0
  149. package/utilities/index.js +1 -0
  150. package/utilities/index.js.map +1 -1
  151. package/utilities/utilities.cjs +57 -9
  152. package/utilities/utilities.cjs.map +1 -1
  153. package/utilities/utilities.cjs.native.js +57 -9
  154. package/version.js +1 -1
@@ -0,0 +1,13 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Create a new `useQueryRefHandlers` hook that returns `refetch` and `fetchMore` functions for a given `queryRef`. This is useful to get access to handlers for a `queryRef` that was created by `createQueryPreloader` or when the handlers for a `queryRef` produced by a different component are inaccessible.
6
+
7
+ ```jsx
8
+ const MyComponent({ queryRef }) {
9
+ const { refetch, fetchMore } = useQueryRefHandlers(queryRef);
10
+
11
+ // ...
12
+ }
13
+ ```
@@ -0,0 +1,47 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Allow returning `IGNORE` sentinel object from `optimisticResponse` functions to bail-out from the optimistic update.
6
+
7
+ Consider this example:
8
+
9
+ ```jsx
10
+ const UPDATE_COMMENT = gql`
11
+ mutation UpdateComment($commentId: ID!, $commentContent: String!) {
12
+ updateComment(commentId: $commentId, content: $commentContent) {
13
+ id
14
+ __typename
15
+ content
16
+ }
17
+ }
18
+ `;
19
+
20
+ function CommentPageWithData() {
21
+ const [mutate] = useMutation(UPDATE_COMMENT);
22
+ return (
23
+ <Comment
24
+ updateComment={({ commentId, commentContent }) =>
25
+ mutate({
26
+ variables: { commentId, commentContent },
27
+ optimisticResponse: (vars, { IGNORE }) => {
28
+ if (commentContent === "foo") {
29
+ // conditionally bail out of optimistic updates
30
+ return IGNORE;
31
+ }
32
+ return {
33
+ updateComment: {
34
+ id: commentId,
35
+ __typename: "Comment",
36
+ content: commentContent
37
+ }
38
+ }
39
+ },
40
+ })
41
+ }
42
+ />
43
+ );
44
+ }
45
+ ```
46
+
47
+ The `IGNORE` sentinel can be destructured from the second parameter in the callback function signature passed to `optimisticResponse`.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "mode": "pre",
3
- "tag": "alpha",
3
+ "tag": "beta",
4
4
  "initialVersions": {
5
5
  "@apollo/client": "3.8.3"
6
6
  },
@@ -10,19 +10,27 @@
10
10
  "clean-items-smash",
11
11
  "cold-llamas-turn",
12
12
  "dirty-kids-crash",
13
+ "dirty-tigers-matter",
13
14
  "forty-cups-shop",
14
15
  "friendly-clouds-laugh",
15
16
  "hot-ducks-burn",
17
+ "mighty-coats-check",
16
18
  "polite-avocados-warn",
17
19
  "quick-hats-marry",
20
+ "rare-snakes-melt",
18
21
  "shaggy-ears-scream",
19
22
  "shaggy-sheep-pull",
20
23
  "sixty-boxes-rest",
21
24
  "sour-sheep-walk",
22
25
  "strong-terms-perform",
26
+ "swift-zoos-collect",
23
27
  "thick-mice-collect",
28
+ "thick-tips-cry",
24
29
  "thirty-ties-arrive",
30
+ "tough-timers-begin",
31
+ "unlucky-rats-decide",
25
32
  "violet-lions-draw",
33
+ "wet-forks-rhyme",
26
34
  "wild-dolphins-jog",
27
35
  "yellow-flies-repeat"
28
36
  ]
@@ -0,0 +1,24 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Add the ability to start preloading a query outside React to begin fetching as early as possible. Call `createQueryPreloader` to create a `preloadQuery` function which can be called to start fetching a query. This returns a `queryRef` which is passed to `useReadQuery` and suspended until the query is done fetching.
6
+
7
+ ```tsx
8
+ const preloadQuery = createQueryPreloader(client);
9
+ const queryRef = preloadQuery(QUERY, { variables, ...otherOptions });
10
+
11
+ function App() {
12
+ return {
13
+ <Suspense fallback={<div>Loading</div>}>
14
+ <MyQuery />
15
+ </Suspense>
16
+ }
17
+ }
18
+
19
+ function MyQuery() {
20
+ const { data } = useReadQuery(queryRef);
21
+
22
+ // do something with data
23
+ }
24
+ ```
@@ -0,0 +1,19 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Adds a new `skipPollAttempt` callback function that's called whenever a refetch attempt occurs while polling. If the function returns `true`, the refetch is skipped and not reattempted until the next poll interval. This will solve the frequent use-case of disabling polling when the window is inactive.
6
+
7
+ ```ts
8
+ useQuery(QUERY, {
9
+ pollInterval: 1000,
10
+ skipPollAttempt: () => document.hidden // or !document.hasFocus()
11
+ });
12
+ // or define it globally
13
+ new ApolloClient({
14
+ defaultOptions: {
15
+ watchQuery: {
16
+ skipPollAttempt: () => document.hidden // or !document.hasFocus()
17
+ }
18
+ }
19
+ })
@@ -0,0 +1,9 @@
1
+ ---
2
+ "@apollo/client": patch
3
+ ---
4
+
5
+ Persisted Query Link: improve memory management
6
+ * use LRU `WeakCache` instead of `WeakMap` to keep a limited number of hash results
7
+ * hash cache is initiated lazily, only when needed
8
+ * expose `persistedLink.resetHashCache()` method
9
+ * reset hash cache if the upstream server reports it doesn't accept persisted queries
@@ -0,0 +1,8 @@
1
+ ---
2
+ "@apollo/client": minor
3
+ ---
4
+
5
+ Deprecates `canonizeResults`.
6
+
7
+ Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option anymore.
8
+ A future version of Apollo Client will contain a similar feature without the risk of memory leaks.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@apollo/client": patch
3
+ ---
4
+
5
+ use WeakMap in React Native with Hermes
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@apollo/client": patch
3
+ ---
4
+
5
+ Adds an experimental `ApolloClient.getMemoryInternals` helper
package/CHANGELOG.md CHANGED
@@ -1,5 +1,119 @@
1
1
  # @apollo/client
2
2
 
3
+ ## 3.9.0-beta.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#11412](https://github.com/apollographql/apollo-client/pull/11412) [`58db5c3`](https://github.com/apollographql/apollo-client/commit/58db5c3295b88162f91019f0898f6baa4b9cced6) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Create a new `useQueryRefHandlers` hook that returns `refetch` and `fetchMore` functions for a given `queryRef`. This is useful to get access to handlers for a `queryRef` that was created by `createQueryPreloader` or when the handlers for a `queryRef` produced by a different component are inaccessible.
8
+
9
+ ```jsx
10
+ const MyComponent({ queryRef }) {
11
+ const { refetch, fetchMore } = useQueryRefHandlers(queryRef);
12
+
13
+ // ...
14
+ }
15
+ ```
16
+
17
+ - [#11410](https://github.com/apollographql/apollo-client/pull/11410) [`07fcf6a`](https://github.com/apollographql/apollo-client/commit/07fcf6a3bf5bc78ffe6f3e598897246b4da02cbb) Thanks [@sf-twingate](https://github.com/sf-twingate)! - Allow returning `IGNORE` sentinel object from `optimisticResponse` functions to bail-out from the optimistic update.
18
+
19
+ Consider this example:
20
+
21
+ ```jsx
22
+ const UPDATE_COMMENT = gql`
23
+ mutation UpdateComment($commentId: ID!, $commentContent: String!) {
24
+ updateComment(commentId: $commentId, content: $commentContent) {
25
+ id
26
+ __typename
27
+ content
28
+ }
29
+ }
30
+ `;
31
+
32
+ function CommentPageWithData() {
33
+ const [mutate] = useMutation(UPDATE_COMMENT);
34
+ return (
35
+ <Comment
36
+ updateComment={({ commentId, commentContent }) =>
37
+ mutate({
38
+ variables: { commentId, commentContent },
39
+ optimisticResponse: (vars, { IGNORE }) => {
40
+ if (commentContent === "foo") {
41
+ // conditionally bail out of optimistic updates
42
+ return IGNORE;
43
+ }
44
+ return {
45
+ updateComment: {
46
+ id: commentId,
47
+ __typename: "Comment",
48
+ content: commentContent,
49
+ },
50
+ };
51
+ },
52
+ })
53
+ }
54
+ />
55
+ );
56
+ }
57
+ ```
58
+
59
+ The `IGNORE` sentinel can be destructured from the second parameter in the callback function signature passed to `optimisticResponse`.
60
+
61
+ - [#11412](https://github.com/apollographql/apollo-client/pull/11412) [`58db5c3`](https://github.com/apollographql/apollo-client/commit/58db5c3295b88162f91019f0898f6baa4b9cced6) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Add the ability to start preloading a query outside React to begin fetching as early as possible. Call `createQueryPreloader` to create a `preloadQuery` function which can be called to start fetching a query. This returns a `queryRef` which is passed to `useReadQuery` and suspended until the query is done fetching.
62
+
63
+ ```tsx
64
+ const preloadQuery = createQueryPreloader(client);
65
+ const queryRef = preloadQuery(QUERY, { variables, ...otherOptions });
66
+
67
+ function App() {
68
+ return {
69
+ <Suspense fallback={<div>Loading</div>}>
70
+ <MyQuery />
71
+ </Suspense>
72
+ }
73
+ }
74
+
75
+ function MyQuery() {
76
+ const { data } = useReadQuery(queryRef);
77
+
78
+ // do something with data
79
+ }
80
+ ```
81
+
82
+ - [#11397](https://github.com/apollographql/apollo-client/pull/11397) [`3f7eecb`](https://github.com/apollographql/apollo-client/commit/3f7eecbfbd4f4444cffcaac7dd9fd225c8c2a401) Thanks [@aditya-kumawat](https://github.com/aditya-kumawat)! - Adds a new `skipPollAttempt` callback function that's called whenever a refetch attempt occurs while polling. If the function returns `true`, the refetch is skipped and not reattempted until the next poll interval. This will solve the frequent use-case of disabling polling when the window is inactive.
83
+
84
+ ```ts
85
+ useQuery(QUERY, {
86
+ pollInterval: 1000,
87
+ skipPollAttempt: () => document.hidden, // or !document.hasFocus()
88
+ });
89
+ // or define it globally
90
+ new ApolloClient({
91
+ defaultOptions: {
92
+ watchQuery: {
93
+ skipPollAttempt: () => document.hidden, // or !document.hasFocus()
94
+ },
95
+ },
96
+ });
97
+ ```
98
+
99
+ - [#11435](https://github.com/apollographql/apollo-client/pull/11435) [`5cce53e`](https://github.com/apollographql/apollo-client/commit/5cce53e83b976f85d2d2b06e28cc38f01324fea1) Thanks [@phryneas](https://github.com/phryneas)! - Deprecates `canonizeResults`.
100
+
101
+ Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option anymore.
102
+ A future version of Apollo Client will contain a similar feature without the risk of memory leaks.
103
+
104
+ ### Patch Changes
105
+
106
+ - [#11369](https://github.com/apollographql/apollo-client/pull/11369) [`2a47164`](https://github.com/apollographql/apollo-client/commit/2a471646616e3af1b5c039e961f8d5717fad8f32) Thanks [@phryneas](https://github.com/phryneas)! - Persisted Query Link: improve memory management
107
+
108
+ - use LRU `WeakCache` instead of `WeakMap` to keep a limited number of hash results
109
+ - hash cache is initiated lazily, only when needed
110
+ - expose `persistedLink.resetHashCache()` method
111
+ - reset hash cache if the upstream server reports it doesn't accept persisted queries
112
+
113
+ - [#10804](https://github.com/apollographql/apollo-client/pull/10804) [`221dd99`](https://github.com/apollographql/apollo-client/commit/221dd99ffd1990f8bd0392543af35e9b08d0fed8) Thanks [@phryneas](https://github.com/phryneas)! - use WeakMap in React Native with Hermes
114
+
115
+ - [#11409](https://github.com/apollographql/apollo-client/pull/11409) [`2e7203b`](https://github.com/apollographql/apollo-client/commit/2e7203b3a9618952ddb522627ded7cceabd7f250) Thanks [@phryneas](https://github.com/phryneas)! - Adds an experimental `ApolloClient.getMemoryInternals` helper
116
+
3
117
  ## 3.9.0-alpha.5
4
118
 
5
119
  ### Minor Changes
@@ -95,7 +209,7 @@
95
209
  import { Environment, Network, RecordSource, Store } from "relay-runtime";
96
210
 
97
211
  const fetchMultipartSubs = createFetchMultipartSubscription(
98
- "http://localhost:4000"
212
+ "http://localhost:4000",
99
213
  );
100
214
 
101
215
  const network = Network.create(fetchQuery, fetchMultipartSubs);
@@ -377,7 +491,7 @@
377
491
  return data.breeds.map(({ characteristics }) =>
378
492
  characteristics.map((characteristic) => (
379
493
  <div key={characteristic}>{characteristic}</div>
380
- ))
494
+ )),
381
495
  );
382
496
  }
383
497
  ```
@@ -428,7 +542,7 @@
428
542
 
429
543
  const { data } = useSuspenseQuery(
430
544
  query,
431
- id ? { variables: { id } } : skipToken
545
+ id ? { variables: { id } } : skipToken,
432
546
  );
433
547
  ```
434
548
 
@@ -2383,7 +2497,7 @@ In upcoming v3.6.x and v3.7 (beta) releases, we will be completely overhauling o
2383
2497
  fields: {
2384
2498
  comments(comments: Reference[], { readField }) {
2385
2499
  return comments.filter(
2386
- (comment) => idToRemove !== readField("id", comment)
2500
+ (comment) => idToRemove !== readField("id", comment),
2387
2501
  );
2388
2502
  },
2389
2503
  },