UNPKG

strip-typename

Version:

Strip typename property from Apollo GraphQL objects

19 lines (18 loc) 529 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const stripTypename = (obj) => { if (Array.isArray(obj)) { return obj.map(stripTypename); } const copy = Object.assign({}, obj); if (copy.hasOwnProperty('__typename')) { delete copy.__typename; } for (const [key, value] of Object.entries(copy)) { if (value && typeof value === 'object') { copy[key] = stripTypename(value); } } return copy; }; exports.default = stripTypename;