debian-mirror-gitlab/spec/frontend/__helpers__/graphql_helpers.js

15 lines
462 B
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
/**
* Returns a clone of the given object with all __typename keys omitted,
* including deeply nested ones.
*
* Only works with JSON-serializable objects.
*
* @param {object} An object with __typename keys (e.g., a GraphQL response)
* @returns {object} A new object with no __typename keys
*/
export const stripTypenames = (object) => {
return JSON.parse(
JSON.stringify(object, (key, value) => (key === '__typename' ? undefined : value)),
);
};