Skip to content

Commit

Permalink
Fix __typename detection in EntityStore#delete.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed May 18, 2020
1 parent 66bb709 commit ca8123e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/cache/inmemory/entityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,17 @@ export abstract class EntityStore implements NormalizedCache {
fieldName?: string,
args?: Record<string, any>,
) {
const storeFieldName = fieldName && args
? this.policies.getStoreFieldName(dataId, fieldName, args)
: fieldName;
return this.modify(dataId, storeFieldName ? {
[storeFieldName]: delModifier,
} : delModifier);
const storeObject = this.lookup(dataId);
if (storeObject) {
const typename = this.getFieldValue<string>(storeObject, "__typename");
const storeFieldName = fieldName && args
? this.policies.getStoreFieldName(typename, fieldName, args)
: fieldName;
return this.modify(dataId, storeFieldName ? {
[storeFieldName]: delModifier,
} : delModifier);
}
return false;
}

public evict(options: Cache.EvictOptions): boolean {
Expand Down
1 change: 0 additions & 1 deletion src/cache/inmemory/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface NormalizedCache {
get(dataId: string, fieldName: string): StoreValue;
merge(dataId: string, incoming: StoreObject): void;
modify(dataId: string, modifiers: Modifier<any> | Modifiers): boolean;
delete(dataId: string, fieldName?: string): boolean;
clear(): void;

// non-Map elements:
Expand Down

0 comments on commit ca8123e

Please sign in to comment.