Skip to content

Commit

Permalink
Expose data on write and writeOptimistic results
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Mar 13, 2020
1 parent 4c1a9c2 commit a401b4c
Showing 1 changed file with 7 additions and 5 deletions.
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 a401b4c

Please sign in to comment.