update get rid of

This commit is contained in:
Pawel Kowalski 2018-09-04 18:08:06 +02:00
parent e9897911b3
commit 12d8d2375c
1 changed files with 4 additions and 2 deletions

View File

@ -15,14 +15,16 @@ Vue.config.productionTip = false
// TODO: Move into a separate project as a plugin
//
function getRidOfEdges(collection) {
if (typeof collection === 'object') {
if (typeof collection === 'object' && collection) {
let newObj = {}
for (const k in collection) {
if (k === 'edges') {
return collection.edges.map(edge => getRidOfEdges(edge.node));
} else {
newObj[k] = getRidOfEdges(collection[k])
delete newObj[k]['__typename']
if (newObj[k]) {
delete newObj[k]['__typename']
}
}
}
return newObj