Skip to content

Commit

Permalink
Fix bug where if you first start the exchanges with server offline, i…
Browse files Browse the repository at this point in the history
…t will never show optimistic results

Also use a cache-only requestPolicy to prevent refetching queries every time. It seems that cache-first
gets upgraded to cache-and-network by graphcache upon receiving a mutation result. It's not known why
it decides to do this right now.

This was caused by the dedup exchange filtering out the reexecuted queries, believe them to
be extraneous. It would never see the OperationResult coming back since server offline causes uncaught
errors to be thrown from the fetch exchange. That in turn causes no errored results to come back.

The easy fix is to simply place queries on the rebound channel, rather than reexecuting them
through the client. Whether or not this is "correct" is hard to say.

The underlying fix should be tracked via urql-graphql/urql#2234
  • Loading branch information
dvicory committed Feb 16, 2022
1 parent a066f8b commit e8c8e70
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/exchanges/crdtExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class CrdtManager {
const dependentQueries = new Set<QueryOperation>();
this.collectDependentQueries(dependentQueries, mutation);
for (const dependentQuery of dependentQueries) {
this.#client.reexecuteOperation(toRequestPolicy(dependentQuery, 'cache-first'));
this.#next(toRequestPolicy(dependentQuery, 'cache-only'));
}

if (!this.#unsubscribe) {
Expand Down Expand Up @@ -484,7 +484,7 @@ class CrdtManager {
this.updateOptimisticState(this.#mutations.values());

for (const dependentQuery of dependentQueries) {
this.#client.reexecuteOperation(toRequestPolicy(dependentQuery, 'cache-first'));
this.#next(toRequestPolicy(dependentQuery, 'cache-only'));
}
}

Expand Down

0 comments on commit e8c8e70

Please sign in to comment.