Skip to content

Commit

Permalink
fix(graphcache): fix restoring variables on mutation operations (#3046)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Mar 14, 2023
1 parent c8b0623 commit d41fac8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fifty-jeans-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/exchange-graphcache': patch
---

Restore variables correctly on mutations
7 changes: 6 additions & 1 deletion exchanges/graphcache/src/cacheExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const cacheExchange = <C extends Partial<CacheExchangeOpts>>(
)
: operation.variables,
},
operation.context
{ ...operation.context, originalVariables: operation.variables }
);
};

Expand Down Expand Up @@ -208,6 +208,11 @@ export const cacheExchange = <C extends Partial<CacheExchangeOpts>>(
: result.operation;

if (operation.kind === 'mutation') {
if (result.operation.context.originalVariables) {
operation.variables = result.operation.context.originalVariables;
delete result.operation.context.originalVariables;
}

// Collect previous dependencies that have been written for optimistic updates
const dependencies = optimisticKeysToDependencies.get(operation.key);
collectPendingOperations(pendingOperations, dependencies);
Expand Down

0 comments on commit d41fac8

Please sign in to comment.