skillbox/client/src/plugins/edges.js

29 lines
694 B
JavaScript

const getRidOfEdges = (collection) => {
if (typeof collection === 'object' && collection && !Array.isArray(collection)) {
let newObj = {};
for (const k in collection) {
if (collection.hasOwnProperty(k)) {
if (k === 'edges') {
return collection.edges.map(edge => getRidOfEdges(edge.node));
} else {
newObj[k] = getRidOfEdges(collection[k]);
if (newObj[k]) {
// delete newObj[k]['__typename']
}
}
}
}
return newObj
} else {
return collection
}
};
const EdgesPlugin = {
install(Vue, options) {
Vue.prototype.$getRidOfEdges = getRidOfEdges;
}
};
export default EdgesPlugin;