Skip to content

Instantly share code, notes, and snippets.

@AndrewIngram
Created October 27, 2022 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewIngram/6ec62d3e37453284a4e1d0e175531156 to your computer and use it in GitHub Desktop.
Save AndrewIngram/6ec62d3e37453284a4e1d0e175531156 to your computer and use it in GitHub Desktop.
Fix object returned from GraphQL-js to work without intermediate serialization
import { mergeWith } from "lodash";
export function nullPrototypeFix(object: Object): Object {
return mergeWith({}, object, (a: any, b: any) => {
if (b === null || typeof b === "undefined") {
return b;
} else if (typeof b.toJSON == "function") {
return b.toJSON();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment