Created
October 27, 2022 18:25
-
-
Save AndrewIngram/6ec62d3e37453284a4e1d0e175531156 to your computer and use it in GitHub Desktop.
Fix object returned from GraphQL-js to work without intermediate serialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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