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

Remove dependency on fast-json-stable-stringify #8222

Merged
merged 8 commits into from
May 18, 2021
23 changes: 22 additions & 1 deletion src/utilities/graphql/storeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export function getStoreKeyName(
fieldName: string,
args?: Record<string, any> | null,
directives?: Directives,
stringify: (value: any) => string = JSON.stringify,
): string {
if (
args &&
Expand Down Expand Up @@ -234,6 +233,28 @@ export function getStoreKeyName(
return completeFieldName;
}

export namespace getStoreKeyName {
brainkim marked this conversation as resolved.
Show resolved Hide resolved
export function setStringify(s: typeof stringify) {
const previous = stringify;
stringify = s;
return previous;
}
}

let stringify = function defaultStringify(value: any): string {
benjamn marked this conversation as resolved.
Show resolved Hide resolved
return JSON.stringify(value, stringifyReplacer);
};

function stringifyReplacer(_key: string, value: any): any {
if (value && typeof value === "object" && !Array.isArray(value)) {
value = Object.keys(value).sort().reduce((copy, key) => {
copy[key] = value[key];
return copy;
}, Object.create(Object.getPrototypeOf(value)));
benjamn marked this conversation as resolved.
Show resolved Hide resolved
}
return value;
}

export function argumentsObjectFromField(
field: FieldNode | DirectiveNode,
variables?: Record<string, any>,
Expand Down