Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Respect additionalTypenames option on subscriptions #3230

Merged
merged 2 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-melons-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/core': patch
---

Respect `additionalTypenames` on subscriptions and re-execute queries for them as well, as one would intuitively expect.
17 changes: 13 additions & 4 deletions packages/core/src/exchanges/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,21 @@ export const cacheExchange: Exchange = ({ forward, client, dispatchDebug }) => {
let { operation } = response;
if (!operation) return;

const typenames = collectTypesFromResponse(response.data).concat(
operation.context.additionalTypenames || []
);
let typenames = operation.context.additionalTypenames || [];
// NOTE: For now, we only respect `additionalTypenames` from subscriptions to
// avoid unexpected breaking changes
// We'd expect live queries or other update mechanisms to be more suitable rather
// than using subscriptions as “signals” to reexecute queries. However, if they’re
// just used as signals, it’s intuitive to hook them up using `additionalTypenames`
if (response.operation.kind !== 'subscription') {
typenames = collectTypesFromResponse(response.data).concat(typenames);
}

// Invalidates the cache given a mutation's response
if (response.operation.kind === 'mutation') {
if (
response.operation.kind === 'mutation' ||
response.operation.kind === 'subscription'
) {
const pendingOperations = new Set<number>();

dispatchDebug({
Expand Down