@apollo/client 3.9.0-alpha.5 → 3.9.0-beta.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/.changeset/chatty-comics-yawn.md +8 -0
- package/.changeset/curvy-seas-hope.md +13 -0
- package/.changeset/dirty-tigers-matter.md +13 -0
- package/.changeset/late-rabbits-protect.md +7 -0
- package/.changeset/mighty-coats-check.md +47 -0
- package/.changeset/pre.json +15 -1
- package/.changeset/rare-snakes-melt.md +24 -0
- package/.changeset/smooth-plums-shout.md +5 -0
- package/.changeset/spicy-drinks-camp.md +5 -0
- package/.changeset/swift-zoos-collect.md +19 -0
- package/.changeset/thick-tips-cry.md +9 -0
- package/.changeset/tough-timers-begin.md +8 -0
- package/.changeset/unlucky-rats-decide.md +5 -0
- package/.changeset/wet-forks-rhyme.md +5 -0
- package/.changeset/wise-news-grab.md +7 -0
- package/CHANGELOG.md +151 -4
- package/apollo-client.cjs +337 -88
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +78 -6
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +78 -6
- package/cache/core/cache.d.ts +9 -0
- package/cache/core/cache.js +11 -2
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +7 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +12 -0
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/core/types/common.d.ts +4 -0
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/fragmentRegistry.js +19 -3
- package/cache/inmemory/fragmentRegistry.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +9 -0
- package/cache/inmemory/inMemoryCache.js +8 -2
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/readFromStore.js +7 -3
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +18 -0
- package/cache/inmemory/types.js.map +1 -1
- package/core/ApolloClient.d.ts +82 -0
- package/core/ApolloClient.js +4 -0
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +2 -0
- package/core/ObservableQuery.js +15 -5
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +1 -0
- package/core/QueryInfo.js +4 -0
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +1 -1
- package/core/QueryManager.js +15 -10
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +107 -16
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +107 -16
- package/core/watchQueryOptions.d.ts +20 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/link/core/ApolloLink.d.ts +15 -0
- package/link/core/ApolloLink.js +8 -4
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/core.cjs +8 -4
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +8 -4
- package/link/persisted-queries/index.d.ts +11 -1
- package/link/persisted-queries/index.js +28 -3
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +26 -3
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +26 -3
- package/link/remove-typename/remove-typename.cjs +18 -2
- package/link/remove-typename/remove-typename.cjs.map +1 -1
- package/link/remove-typename/remove-typename.cjs.native.js +18 -2
- package/link/remove-typename/removeTypenameFromVariables.d.ts +9 -1
- package/link/remove-typename/removeTypenameFromVariables.js +19 -3
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/link/retry/retry.cjs +15 -74
- package/link/retry/retry.cjs.map +1 -1
- package/link/retry/retry.cjs.native.js +15 -74
- package/link/retry/retryLink.js +15 -93
- package/link/retry/retryLink.js.map +1 -1
- package/package.json +21 -21
- package/react/components/Mutation.d.ts +6 -0
- package/react/components/Mutation.js +6 -0
- package/react/components/Mutation.js.map +1 -1
- package/react/components/Query.d.ts +6 -0
- package/react/components/Query.js +6 -0
- package/react/components/Query.js.map +1 -1
- package/react/components/Subscription.d.ts +6 -0
- package/react/components/Subscription.js +6 -0
- package/react/components/Subscription.js.map +1 -1
- package/react/components/components.cjs.map +1 -1
- package/react/hoc/graphql.d.ts +5 -0
- package/react/hoc/graphql.js +5 -0
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/mutation-hoc.d.ts +5 -0
- package/react/hoc/mutation-hoc.js +5 -0
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.d.ts +5 -0
- package/react/hoc/query-hoc.js +5 -0
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.d.ts +5 -0
- package/react/hoc/subscription-hoc.js +5 -0
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/withApollo.d.ts +5 -0
- package/react/hoc/withApollo.js +5 -0
- package/react/hoc/withApollo.js.map +1 -1
- package/react/hooks/hooks.cjs +48 -257
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +48 -257
- package/react/hooks/index.d.ts +2 -0
- package/react/hooks/index.js +1 -0
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +13 -10
- package/react/hooks/useBackgroundQuery.js +2 -4
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +2 -2
- package/react/hooks/useLoadableQuery.js +2 -4
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +35 -0
- package/react/hooks/useQueryRefHandlers.js +48 -0
- package/react/hooks/useQueryRefHandlers.js.map +1 -0
- package/react/hooks/useReadQuery.d.ts +1 -1
- package/react/hooks/useReadQuery.js +8 -2
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +1 -1
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/index.d.ts +2 -0
- package/react/index.js +1 -0
- package/react/index.js.map +1 -1
- package/react/{cache → internal/cache}/QueryReference.d.ts +13 -7
- package/react/{cache → internal/cache}/QueryReference.js +93 -57
- package/react/internal/cache/QueryReference.js.map +1 -0
- package/react/{cache → internal/cache}/SuspenseCache.d.ts +1 -1
- package/react/{cache → internal/cache}/SuspenseCache.js +1 -1
- package/react/internal/cache/SuspenseCache.js.map +1 -0
- package/react/{cache → internal/cache}/getSuspenseCache.d.ts +3 -3
- package/react/internal/cache/getSuspenseCache.js.map +1 -0
- package/react/internal/cache/types.js.map +1 -0
- package/react/internal/index.d.ts +6 -0
- package/react/internal/index.js +3 -0
- package/react/internal/index.js.map +1 -0
- package/react/internal/internal.cjs +283 -0
- package/react/internal/internal.cjs.map +1 -0
- package/react/internal/internal.cjs.native.js +283 -0
- package/react/internal/package.json +8 -0
- package/react/parser/index.js +6 -3
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +11 -3
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +11 -3
- package/react/query-preloader/createQueryPreloader.d.ts +253 -0
- package/react/query-preloader/createQueryPreloader.js +29 -0
- package/react/query-preloader/createQueryPreloader.js.map +1 -0
- package/react/react.cjs +14 -2
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +14 -2
- package/react/types/types.d.ts +7 -1
- package/react/types/types.js.map +1 -1
- package/testing/internal/ObservableStream.js +16 -8
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/internal/index.d.ts +4 -0
- package/testing/internal/index.js +2 -0
- package/testing/internal/index.js.map +1 -1
- package/testing/internal/renderHelpers.d.ts +12 -0
- package/testing/internal/renderHelpers.js +22 -0
- package/testing/internal/renderHelpers.js.map +1 -0
- package/testing/internal/scenarios/index.d.ts +41 -0
- package/testing/internal/scenarios/index.js +48 -0
- package/testing/internal/scenarios/index.js.map +1 -0
- package/testing/matchers/index.js +2 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toBeDisposed.d.ts +3 -0
- package/testing/matchers/toBeDisposed.js +26 -0
- package/testing/matchers/toBeDisposed.js.map +1 -0
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.js +1 -1
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
- package/utilities/caching/caches.d.ts +34 -0
- package/utilities/caching/caches.js +64 -0
- package/utilities/caching/caches.js.map +1 -0
- package/utilities/caching/getMemoryInternals.d.ts +76 -0
- package/utilities/caching/getMemoryInternals.js +112 -0
- package/utilities/caching/getMemoryInternals.js.map +1 -0
- package/utilities/caching/index.d.ts +4 -0
- package/utilities/caching/index.js +3 -0
- package/utilities/caching/index.js.map +1 -0
- package/utilities/caching/sizes.d.ts +311 -0
- package/utilities/caching/sizes.js +27 -0
- package/utilities/caching/sizes.js.map +1 -0
- package/utilities/common/canUse.js +1 -1
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/canonicalStringify.js +8 -2
- package/utilities/common/canonicalStringify.js.map +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/graphql/DocumentTransform.d.ts +14 -1
- package/utilities/graphql/DocumentTransform.js +9 -5
- package/utilities/graphql/DocumentTransform.js.map +1 -1
- package/utilities/graphql/print.js +6 -2
- package/utilities/graphql/print.js.map +1 -1
- package/utilities/index.d.ts +2 -0
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/utilities.cjs +57 -9
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +57 -9
- package/version.js +1 -1
- package/react/cache/QueryReference.js.map +0 -1
- package/react/cache/SuspenseCache.js.map +0 -1
- package/react/cache/getSuspenseCache.js.map +0 -1
- package/react/cache/index.d.ts +0 -3
- package/react/cache/index.js +0 -2
- package/react/cache/index.js.map +0 -1
- package/react/cache/types.js.map +0 -1
- /package/react/{cache → internal/cache}/getSuspenseCache.js +0 -0
- /package/react/{cache → internal/cache}/types.d.ts +0 -0
- /package/react/{cache → internal/cache}/types.js +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@apollo/client": minor
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Simplify RetryLink, fix potential memory leak
|
|
6
|
+
|
|
7
|
+
Historically, `RetryLink` would keep a `values` array of all previous values,
|
|
8
|
+
in case the operation would get an additional subscriber at a later point in time.
|
|
9
|
+
In practice, this could lead to a memory leak (#11393) and did not serve any
|
|
10
|
+
further purpose, as the resulting observable would only be subscribed to by
|
|
11
|
+
Apollo Client itself, and only once - it would be wrapped in a `Concast` before
|
|
12
|
+
being exposed to the user, and that `Concast` would handle subscribers on its
|
|
13
|
+
own.
|
|
@@ -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,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
'@apollo/client': minor
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Remove the need to call `retain` from `useLoadableQuery` since `useReadQuery` will now retain the query. This means that a `queryRef` that is not consumed by `useReadQuery` within the given `autoDisposeTimeoutMs` will now be auto diposed for you.
|
|
6
|
+
|
|
7
|
+
Thanks to [#11412](https://github.com/apollographql/apollo-client/pull/11412), disposed query refs will be automatically resubscribed to the query when consumed by `useReadQuery` after it has been disposed.
|
|
@@ -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`.
|
package/.changeset/pre.json
CHANGED
|
@@ -1,29 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"mode": "pre",
|
|
3
|
-
"tag": "
|
|
3
|
+
"tag": "beta",
|
|
4
4
|
"initialVersions": {
|
|
5
5
|
"@apollo/client": "3.8.3"
|
|
6
6
|
},
|
|
7
7
|
"changesets": [
|
|
8
8
|
"beige-geese-wink",
|
|
9
9
|
"breezy-spiders-tap",
|
|
10
|
+
"chatty-comics-yawn",
|
|
10
11
|
"clean-items-smash",
|
|
11
12
|
"cold-llamas-turn",
|
|
13
|
+
"curvy-seas-hope",
|
|
12
14
|
"dirty-kids-crash",
|
|
15
|
+
"dirty-tigers-matter",
|
|
13
16
|
"forty-cups-shop",
|
|
14
17
|
"friendly-clouds-laugh",
|
|
15
18
|
"hot-ducks-burn",
|
|
19
|
+
"late-rabbits-protect",
|
|
20
|
+
"mighty-coats-check",
|
|
16
21
|
"polite-avocados-warn",
|
|
17
22
|
"quick-hats-marry",
|
|
23
|
+
"rare-snakes-melt",
|
|
18
24
|
"shaggy-ears-scream",
|
|
19
25
|
"shaggy-sheep-pull",
|
|
20
26
|
"sixty-boxes-rest",
|
|
27
|
+
"smooth-plums-shout",
|
|
21
28
|
"sour-sheep-walk",
|
|
29
|
+
"spicy-drinks-camp",
|
|
22
30
|
"strong-terms-perform",
|
|
31
|
+
"swift-zoos-collect",
|
|
23
32
|
"thick-mice-collect",
|
|
33
|
+
"thick-tips-cry",
|
|
24
34
|
"thirty-ties-arrive",
|
|
35
|
+
"tough-timers-begin",
|
|
36
|
+
"unlucky-rats-decide",
|
|
25
37
|
"violet-lions-draw",
|
|
38
|
+
"wet-forks-rhyme",
|
|
26
39
|
"wild-dolphins-jog",
|
|
40
|
+
"wise-news-grab",
|
|
27
41
|
"yellow-flies-repeat"
|
|
28
42
|
]
|
|
29
43
|
}
|
|
@@ -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,5 @@
|
|
|
1
|
+
---
|
|
2
|
+
'@apollo/client': patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Address bundling issue introduced in [#11412](https://github.com/apollographql/apollo-client/pull/11412) where the `react/cache` internals ended up duplicated in the bundle. This was due to the fact that we had a `react/hooks` entrypoint that imported these files along with the newly introduced `createQueryPreloader` function, which lived outside of the `react/hooks` folder.
|
|
@@ -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,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
'@apollo/client': minor
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Remove the need to call `retain` from `useBackgroundQuery` since `useReadQuery` will now retain the query. This means that a `queryRef` that is not consumed by `useReadQuery` within the given `autoDisposeTimeoutMs` will now be auto diposed for you.
|
|
6
|
+
|
|
7
|
+
Thanks to [#11412](https://github.com/apollographql/apollo-client/pull/11412), disposed query refs will be automatically resubscribed to the query when consumed by `useReadQuery` after it has been disposed.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,152 @@
|
|
|
1
1
|
# @apollo/client
|
|
2
2
|
|
|
3
|
+
## 3.9.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#11424](https://github.com/apollographql/apollo-client/pull/11424) [`62f3b6d`](https://github.com/apollographql/apollo-client/commit/62f3b6d0e89611e27d9f29812ee60e5db5963fd6) Thanks [@phryneas](https://github.com/phryneas)! - Simplify RetryLink, fix potential memory leak
|
|
8
|
+
|
|
9
|
+
Historically, `RetryLink` would keep a `values` array of all previous values,
|
|
10
|
+
in case the operation would get an additional subscriber at a later point in time.
|
|
11
|
+
In practice, this could lead to a memory leak (#11393) and did not serve any
|
|
12
|
+
further purpose, as the resulting observable would only be subscribed to by
|
|
13
|
+
Apollo Client itself, and only once - it would be wrapped in a `Concast` before
|
|
14
|
+
being exposed to the user, and that `Concast` would handle subscribers on its
|
|
15
|
+
own.
|
|
16
|
+
|
|
17
|
+
- [#11442](https://github.com/apollographql/apollo-client/pull/11442) [`4b6f2bc`](https://github.com/apollographql/apollo-client/commit/4b6f2bccf3ba94643b38689b32edd2839e47aec1) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Remove the need to call `retain` from `useLoadableQuery` since `useReadQuery` will now retain the query. This means that a `queryRef` that is not consumed by `useReadQuery` within the given `autoDisposeTimeoutMs` will now be auto diposed for you.
|
|
18
|
+
|
|
19
|
+
Thanks to [#11412](https://github.com/apollographql/apollo-client/pull/11412), disposed query refs will be automatically resubscribed to the query when consumed by `useReadQuery` after it has been disposed.
|
|
20
|
+
|
|
21
|
+
- [#11438](https://github.com/apollographql/apollo-client/pull/11438) [`6d46ab9`](https://github.com/apollographql/apollo-client/commit/6d46ab930a5e9bd5cae153d3b75b8966784fcd4e) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Remove the need to call `retain` from `useBackgroundQuery` since `useReadQuery` will now retain the query. This means that a `queryRef` that is not consumed by `useReadQuery` within the given `autoDisposeTimeoutMs` will now be auto diposed for you.
|
|
22
|
+
|
|
23
|
+
Thanks to [#11412](https://github.com/apollographql/apollo-client/pull/11412), disposed query refs will be automatically resubscribed to the query when consumed by `useReadQuery` after it has been disposed.
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- [#11443](https://github.com/apollographql/apollo-client/pull/11443) [`ff5a332`](https://github.com/apollographql/apollo-client/commit/ff5a332ff8b190c418df25371e36719d70061ebe) Thanks [@phryneas](https://github.com/phryneas)! - Adds a deprecation warning to the HOC and render prop APIs.
|
|
28
|
+
|
|
29
|
+
The HOC and render prop APIs have already been deprecated since 2020,
|
|
30
|
+
but we previously didn't have a @deprecated tag in the DocBlocks.
|
|
31
|
+
|
|
32
|
+
- [#11078](https://github.com/apollographql/apollo-client/pull/11078) [`14edebe`](https://github.com/apollographql/apollo-client/commit/14edebebefb7634c32b921d02c1c85c6c8737989) Thanks [@phryneas](https://github.com/phryneas)! - ObservableQuery: prevent reporting results of previous queries if the variables changed since
|
|
33
|
+
|
|
34
|
+
- [#11439](https://github.com/apollographql/apollo-client/pull/11439) [`33454f0`](https://github.com/apollographql/apollo-client/commit/33454f0a40a05ea2b00633bda20a84d0ec3a4f4d) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Address bundling issue introduced in [#11412](https://github.com/apollographql/apollo-client/pull/11412) where the `react/cache` internals ended up duplicated in the bundle. This was due to the fact that we had a `react/hooks` entrypoint that imported these files along with the newly introduced `createQueryPreloader` function, which lived outside of the `react/hooks` folder.
|
|
35
|
+
|
|
36
|
+
## 3.9.0-beta.0
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- [#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.
|
|
41
|
+
|
|
42
|
+
```jsx
|
|
43
|
+
const MyComponent({ queryRef }) {
|
|
44
|
+
const { refetch, fetchMore } = useQueryRefHandlers(queryRef);
|
|
45
|
+
|
|
46
|
+
// ...
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- [#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.
|
|
51
|
+
|
|
52
|
+
Consider this example:
|
|
53
|
+
|
|
54
|
+
```jsx
|
|
55
|
+
const UPDATE_COMMENT = gql`
|
|
56
|
+
mutation UpdateComment($commentId: ID!, $commentContent: String!) {
|
|
57
|
+
updateComment(commentId: $commentId, content: $commentContent) {
|
|
58
|
+
id
|
|
59
|
+
__typename
|
|
60
|
+
content
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
function CommentPageWithData() {
|
|
66
|
+
const [mutate] = useMutation(UPDATE_COMMENT);
|
|
67
|
+
return (
|
|
68
|
+
<Comment
|
|
69
|
+
updateComment={({ commentId, commentContent }) =>
|
|
70
|
+
mutate({
|
|
71
|
+
variables: { commentId, commentContent },
|
|
72
|
+
optimisticResponse: (vars, { IGNORE }) => {
|
|
73
|
+
if (commentContent === "foo") {
|
|
74
|
+
// conditionally bail out of optimistic updates
|
|
75
|
+
return IGNORE;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
updateComment: {
|
|
79
|
+
id: commentId,
|
|
80
|
+
__typename: "Comment",
|
|
81
|
+
content: commentContent,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The `IGNORE` sentinel can be destructured from the second parameter in the callback function signature passed to `optimisticResponse`.
|
|
93
|
+
|
|
94
|
+
- [#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.
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
const preloadQuery = createQueryPreloader(client);
|
|
98
|
+
const queryRef = preloadQuery(QUERY, { variables, ...otherOptions });
|
|
99
|
+
|
|
100
|
+
function App() {
|
|
101
|
+
return {
|
|
102
|
+
<Suspense fallback={<div>Loading</div>}>
|
|
103
|
+
<MyQuery />
|
|
104
|
+
</Suspense>
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function MyQuery() {
|
|
109
|
+
const { data } = useReadQuery(queryRef);
|
|
110
|
+
|
|
111
|
+
// do something with data
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- [#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.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
useQuery(QUERY, {
|
|
119
|
+
pollInterval: 1000,
|
|
120
|
+
skipPollAttempt: () => document.hidden, // or !document.hasFocus()
|
|
121
|
+
});
|
|
122
|
+
// or define it globally
|
|
123
|
+
new ApolloClient({
|
|
124
|
+
defaultOptions: {
|
|
125
|
+
watchQuery: {
|
|
126
|
+
skipPollAttempt: () => document.hidden, // or !document.hasFocus()
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- [#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`.
|
|
133
|
+
|
|
134
|
+
Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option anymore.
|
|
135
|
+
A future version of Apollo Client will contain a similar feature without the risk of memory leaks.
|
|
136
|
+
|
|
137
|
+
### Patch Changes
|
|
138
|
+
|
|
139
|
+
- [#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
|
|
140
|
+
|
|
141
|
+
- use LRU `WeakCache` instead of `WeakMap` to keep a limited number of hash results
|
|
142
|
+
- hash cache is initiated lazily, only when needed
|
|
143
|
+
- expose `persistedLink.resetHashCache()` method
|
|
144
|
+
- reset hash cache if the upstream server reports it doesn't accept persisted queries
|
|
145
|
+
|
|
146
|
+
- [#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
|
|
147
|
+
|
|
148
|
+
- [#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
|
|
149
|
+
|
|
3
150
|
## 3.9.0-alpha.5
|
|
4
151
|
|
|
5
152
|
### Minor Changes
|
|
@@ -95,7 +242,7 @@
|
|
|
95
242
|
import { Environment, Network, RecordSource, Store } from "relay-runtime";
|
|
96
243
|
|
|
97
244
|
const fetchMultipartSubs = createFetchMultipartSubscription(
|
|
98
|
-
"http://localhost:4000"
|
|
245
|
+
"http://localhost:4000",
|
|
99
246
|
);
|
|
100
247
|
|
|
101
248
|
const network = Network.create(fetchQuery, fetchMultipartSubs);
|
|
@@ -377,7 +524,7 @@
|
|
|
377
524
|
return data.breeds.map(({ characteristics }) =>
|
|
378
525
|
characteristics.map((characteristic) => (
|
|
379
526
|
<div key={characteristic}>{characteristic}</div>
|
|
380
|
-
))
|
|
527
|
+
)),
|
|
381
528
|
);
|
|
382
529
|
}
|
|
383
530
|
```
|
|
@@ -428,7 +575,7 @@
|
|
|
428
575
|
|
|
429
576
|
const { data } = useSuspenseQuery(
|
|
430
577
|
query,
|
|
431
|
-
id ? { variables: { id } } : skipToken
|
|
578
|
+
id ? { variables: { id } } : skipToken,
|
|
432
579
|
);
|
|
433
580
|
```
|
|
434
581
|
|
|
@@ -2383,7 +2530,7 @@ In upcoming v3.6.x and v3.7 (beta) releases, we will be completely overhauling o
|
|
|
2383
2530
|
fields: {
|
|
2384
2531
|
comments(comments: Reference[], { readField }) {
|
|
2385
2532
|
return comments.filter(
|
|
2386
|
-
(comment) => idToRemove !== readField("id", comment)
|
|
2533
|
+
(comment) => idToRemove !== readField("id", comment),
|
|
2387
2534
|
);
|
|
2388
2535
|
},
|
|
2389
2536
|
},
|