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
Hoist normalize function out of extractKeyPath.
  • Loading branch information
benjamn committed Nov 3, 2021
commit 40fbe6293262d7e38214e8fcb2380d68011304f4
32 changes: 16 additions & 16 deletions src/cache/inmemory/key-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ export function extractKeyPath(
path: string[],
extract?: typeof extractKey,
): any {
return (function normalize<T>(value: T): T {
// Usually the extracted value will be a scalar value, since most primary
// key fields are scalar, but just in case we get an object or an array, we
// need to do some normalization of the order of (nested) keys.
if (isNonNullObject(value)) {
if (Array.isArray(value)) {
return value.map(normalize) as any;
}
return collectSpecifierPaths(
Object.keys(value).sort(),
path => extractKeyPath(value, path),
);
return normalize(path.reduce(extract || extractKey, object));
}

function normalize<T>(value: T): T {
// Usually the extracted value will be a scalar value, since most primary
// key fields are scalar, but just in case we get an object or an array, we
// need to do some normalization of the order of (nested) keys.
if (isNonNullObject(value)) {
if (Array.isArray(value)) {
return value.map(normalize) as any;
}
return value;
})(
path.reduce(extract || extractKey, object)
);
return collectSpecifierPaths(
Object.keys(value).sort(),
path => extractKeyPath(value, path),
);
}
return value;
}

function extractKey(
Expand Down