Skip to content

Commit c52be95

Browse files
authored
Add section on query deduplication to migration guide (#12981)
1 parent 0864ff8 commit c52be95

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/source/migrating/apollo-client-4-migration.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,33 @@ useQuery(QUERY, {
10051005
});
10061006
```
10071007
1008+
### Subscription deduplication
1009+
1010+
Subscriptions are now deduplicated when `queryDeduplication` is enabled (the default). Subscriptions that qualify for deduplication attach to the same connection as a previously connected subscription.
1011+
1012+
To disable query deduplication, provide `queryDeduplication: false` to the `context` option when creating the subscription.
1013+
1014+
```ts
1015+
// with React's `useSubscription`
1016+
useSubscription(SUBSCRIPTION, {
1017+
context: { queryDeduplication: false },
1018+
});
1019+
1020+
// with the core API
1021+
const observable = client.subscribe({
1022+
query: SUBSCRIPTION,
1023+
context: { queryDeduplication: false },
1024+
});
1025+
```
1026+
1027+
<Caution>
1028+
1029+
Some GraphQL servers emit an initial value when the subscription first connects. A subscription that attaches to an existing connection because of deduplication does not receive an update until the server next emits a value. Depending on the frequency of updates pushed from the server, the deduplicated subscription might wait for an extended period of time before receiving its first value.<br/><br/>
1030+
1031+
If you rely on the initial value to read data from the subscription, we recommend disabling query deduplication so that the subscription creates a new connection.
1032+
1033+
</Caution>
1034+
10081035
## New error handling
10091036
10101037
Error handling in Apollo Client 4 has changed significantly to be more predictable and intuitive.

0 commit comments

Comments
 (0)