Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify written results using processed StoreObject in StoreWriter#processSelectionSet #8996

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tolerate policies.identify failure when dataId already provided.
  • Loading branch information
benjamn committed Nov 3, 2021
commit 634e21bf25def6740cff6e771783f388fbd403d0
34 changes: 20 additions & 14 deletions src/cache/inmemory/writeToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,22 +365,28 @@ export class StoreWriter {

// Identify the result object, even if dataId was already provided,
// since we always need keyObject below.
const [id, keyObject] = policies.identify(result, {
selectionSet,
fragmentMap: context.fragmentMap,
storeObject: incoming,
readField,
});
try {
const [id, keyObject] = policies.identify(result, {
typename,
selectionSet,
fragmentMap: context.fragmentMap,
storeObject: incoming,
readField,
});

// If dataId was not provided, fall back to the id just generated by
// policies.identify.
dataId = dataId || id;
// If dataId was not provided, fall back to the id just generated by
// policies.identify.
dataId = dataId || id;

// Write any key fields that were used during identification, even if
// they were not mentioned in the original query.
if (keyObject) {
// TODO Reverse the order of the arguments?
incoming = context.merge(incoming, keyObject);
// Write any key fields that were used during identification, even if
// they were not mentioned in the original query.
if (keyObject) {
// TODO Reverse the order of the arguments?
incoming = context.merge(incoming, keyObject);
}
} catch (e) {
// If dataId was provided, tolerate failure of policies.identify.
if (!dataId) throw e;
}

if ("string" === typeof dataId) {
Expand Down