diff --git a/packages/offix-client/src/apollo/optimisticResponseHelpers.ts b/packages/offix-client/src/apollo/optimisticResponseHelpers.ts index b290d11ff..a5c44ba0e 100644 --- a/packages/offix-client/src/apollo/optimisticResponseHelpers.ts +++ b/packages/offix-client/src/apollo/optimisticResponseHelpers.ts @@ -18,11 +18,13 @@ export function addOptimisticResponse(apolloClient: ApolloClient, { 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( @@ -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; @@ -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);