From 717b956c609e631fbf84fea133c4cb75f184b182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phil=20Pl=C3=BCckthun?= Date: Fri, 13 Mar 2020 19:27:13 +0000 Subject: [PATCH] (graphcache) - Expose data on write and writeOptimistic results (#613) * Expose data on write and writeOptimistic results * Add changeset --- .changeset/metal-otters-mate.md | 5 +++++ exchanges/graphcache/src/operations/write.ts | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 .changeset/metal-otters-mate.md diff --git a/.changeset/metal-otters-mate.md b/.changeset/metal-otters-mate.md new file mode 100644 index 0000000000..55a0104250 --- /dev/null +++ b/.changeset/metal-otters-mate.md @@ -0,0 +1,5 @@ +--- +'@urql/exchange-graphcache': patch +--- + +Expose generated result data on writeOptimistic and passthrough data on write operations. 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; };