From a401b4c8f11e93dad3d9cf33fddb06edefc3f844 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 13 Mar 2020 18:13:17 +0000 Subject: [PATCH] Expose data on write and writeOptimistic results --- exchanges/graphcache/src/operations/write.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/exchanges/graphcache/src/operations/write.ts b/exchanges/graphcache/src/operations/write.ts index ea8afaa8db..7d46abfbd2 100644 --- a/exchanges/graphcache/src/operations/write.ts +++ b/exchanges/graphcache/src/operations/write.ts @@ -37,6 +37,7 @@ import { } from './shared'; export interface WriteResult { + data: null | Data; dependencies: Set; } @@ -59,7 +60,7 @@ export const startWrite = ( data: Data ) => { const operation = getMainOperation(request.query); - const result: WriteResult = { dependencies: getCurrentDependencies() }; + const result: WriteResult = { data, dependencies: getCurrentDependencies() }; const operationName = store.rootFields[operation.operation]; const ctx = makeContext( @@ -75,7 +76,6 @@ export const startWrite = ( } writeSelection(ctx, operationName, getSelectionSet(operation), data); - return result; }; @@ -87,7 +87,10 @@ export const writeOptimistic = ( initDataState(store.data, key, true); const operation = getMainOperation(request.query); - const result: WriteResult = { dependencies: getCurrentDependencies() }; + const result: WriteResult = { + data: makeDict(), + dependencies: getCurrentDependencies(), + }; const operationName = store.rootFields[operation.operation]; invariant( @@ -110,8 +113,7 @@ export const writeOptimistic = ( true ); - const data = makeDict(); - writeSelection(ctx, operationName, getSelectionSet(operation), data); + writeSelection(ctx, operationName, getSelectionSet(operation), result.data!); clearDataState(); return result; };