Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 20 additions & 12 deletions src/cache/inmemory/entityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,21 @@ export abstract class EntityStore implements NormalizedCache {
}

public extract(): NormalizedCacheObject {
const obj = Object.fromEntries(
Object.entries(this.toObject()).map(([dataId, storeObject]) => [
dataId,
storeObject &&
this.coerceStoreObject(
storeObject,
(scalar, value) => scalar.coerceToSerialized(value),
storeObject?.__typename || this.policies.rootTypenamesById[dataId]
),
])
);
let obj = this.toObject();

if (this.hasScalarConfig()) {
obj = Object.fromEntries(
Object.entries(obj).map(([dataId, storeObject]) => [
dataId,
storeObject &&
this.coerceStoreObject(
storeObject,
(scalar, value) => scalar.coerceToSerialized(value),
storeObject?.__typename || this.policies.rootTypenamesById[dataId]
),
])
);
}

const extraRootIds: string[] = [];
this.getRootIdSet().forEach((id) => {
Expand All @@ -426,12 +430,16 @@ export abstract class EntityStore implements NormalizedCache {
return obj;
}

private hasScalarConfig() {
return !!this.policies.cache["config"].scalars;
}

private coerceStoreObject(
obj: StoreObject,
coerce: (scalar: Scalar<any, any>, value: unknown) => unknown,
typename = obj.__typename
): StoreObject {
if (!typename || !this.policies.cache["config"].scalars) {
if (!typename || !this.hasScalarConfig()) {
return obj;
}

Expand Down
4 changes: 0 additions & 4 deletions src/cache/inmemory/readFromStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,6 @@ export class StoreReader {
// do nothing
} else if (fieldValue != null) {
if (__DEV__) {
const typename = context.store.getFieldValue<string>(
objectOrReference,
"__typename"
);
const fieldName = selection.name.value;

if (typename) {
Expand Down
Loading