Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
fix: add mixxing check for op being null where mutation is dangling t…
Browse files Browse the repository at this point in the history
…here
  • Loading branch information
wtrocki committed Jul 8, 2020
1 parent b8d144f commit 571aecf
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/offix-client/src/apollo/optimisticResponseHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export function addOptimisticResponse(apolloClient: ApolloClient<NormalizedCache
}

export function removeOptimisticResponse(apolloClient: ApolloClient<NormalizedCacheObject>, { op, qid }: ApolloQueueEntryOperation) {
apolloClient.store.markMutationComplete({
mutationId: qid,
optimisticResponse: op.optimisticResponse
});
apolloClient.queryManager.broadcastQueries();
if (op) {
apolloClient.store.markMutationComplete({
mutationId: qid,
optimisticResponse: op.optimisticResponse
});
apolloClient.queryManager.broadcastQueries();
}
}

export function restoreOptimisticResponse(
Expand All @@ -47,7 +49,7 @@ export function replaceClientGeneratedIDsInQueue(queue: ApolloOfflineQueue, oper

const op = operation.op;
const operationName = op.context.operationName as string;
const optimisticResponse = op.optimisticResponse as {[key: string]: any};
const optimisticResponse = op.optimisticResponse as { [key: string]: any };

if (!optimisticResponse) {
return;
Expand All @@ -65,7 +67,7 @@ export function replaceClientGeneratedIDsInQueue(queue: ApolloOfflineQueue, oper
queue.entries.forEach((entry) => {
// replace all instances of the optimistic id in the queue with
// the new id that came back from the server
traverse(entry.operation.op.variables).forEach(function(val) {
traverse(entry.operation.op.variables).forEach(function (val) {
if (this.isLeaf && val && val === optimisticId) {
this.update(resultId);
queue.updateOperation(entry.operation);
Expand Down

0 comments on commit 571aecf

Please sign in to comment.