Skip to content

Commit

Permalink
Simplify StoreWriter#writeSelectionSetToStore using store.get.
Browse files Browse the repository at this point in the history
Follow-up to #5919 and 9fbcda9.

Now that the policies.rootTypenamesById check happens in store.get, we
don't have to rely on the getFieldValue wrapper to ensure __typename can
always be determined.
  • Loading branch information
benjamn committed Feb 7, 2020
1 parent bd8e958 commit 0c231d1
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/cache/inmemory/writeToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,17 @@ export class StoreWriter {
if (sets.indexOf(selectionSet) >= 0) return store;
sets.push(selectionSet);

const entityRef = makeReference(dataId);
const typename =
// If the result has a __typename, trust that.
getTypenameFromResult(result, selectionSet, context.fragmentMap) ||
// If the entity identified by dataId has a __typename in the store,
// fall back to that.
store.getFieldValue<string>(entityRef, "__typename");
store.get(dataId, "__typename") as string;

store.merge(
dataId,
policies.applyMerges(
entityRef,
makeReference(dataId),
this.processSelectionSet({
result,
selectionSet,
Expand Down

0 comments on commit 0c231d1

Please sign in to comment.