Skip to content

Commit

Permalink
(graphcache) - Expose data on write and writeOptimistic results (#613)
Browse files Browse the repository at this point in the history
* Expose data on write and writeOptimistic results

* Add changeset
  • Loading branch information
kitten authored Mar 13, 2020
1 parent 4c1a9c2 commit 717b956
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-otters-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/exchange-graphcache': patch
---

Expose generated result data on writeOptimistic and passthrough data on write operations.
12 changes: 7 additions & 5 deletions exchanges/graphcache/src/operations/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from './shared';

export interface WriteResult {
data: null | Data;
dependencies: Set<string>;
}

Expand All @@ -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(
Expand All @@ -75,7 +76,6 @@ export const startWrite = (
}

writeSelection(ctx, operationName, getSelectionSet(operation), data);

return result;
};

Expand All @@ -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(
Expand All @@ -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;
};
Expand Down

0 comments on commit 717b956

Please sign in to comment.