Replace specific edge/node removal with a generic solution: move into globally available function.

- Why is it not possible to change data with apollo link?
This commit is contained in:
Pawel Kowalski 2018-08-17 18:08:15 +02:00
parent 17b0047b32
commit ea073a29ac
4 changed files with 43 additions and 24 deletions

View File

@ -8,7 +8,7 @@
</div>
<h3>Lernziele</h3>
<objective-group v-for="group in module.objectiveGroups" :key="group.id" :group="group"></objective-group>
<objective-group v-for="group in module.objectivegroupSet" :key="group.id" :group="group"></objective-group>
<chapter :chapter="chapter" v-for="chapter in module.chapters" :key="chapter.id"></chapter>
<h3>1.1 Lehrbeginn</h3>

View File

@ -3,7 +3,7 @@
<h4>{{group.title}}</h4>
<ul class="objective-group__objective-list">
<li class="objective-group__objective" v-for="objective in group.objectives" :key="objective.id">
<li class="objective-group__objective" v-for="objective in group.objectiveSet" :key="objective.id">
{{objective.text}}
</li>
</ul>

View File

@ -13,6 +13,21 @@ const httpLink = new HttpLink({
}
})
const purgeEdgesNodes = new ApolloLink((operation, forward) => {
return forward(operation).map(response => {
// if (response.data.user.lastLoginDate) {
// response.data.user.lastLoginDate = new Date(
// response.data.user.lastLoginDate
// );
// }
// data.data.modules = ['is_me']
// response.data.modules = ['is_me']
// debugger
return response;
});
});
const consoleLink = new ApolloLink((operation, forward) => {
console.log(`starting request for ${operation.operationName}`);
@ -37,14 +52,16 @@ const consoleLink = new ApolloLink((operation, forward) => {
return forward(operation).map((data) => {
console.log(`ending request for ${operation.operationName}`);
// data.data.modules = ['is_me']
// debugger
// let data = getRidOfEdges(inData)
// return resultData;
return data
})
})
const composedLink = ApolloLink.from([consoleLink, httpLink]);
const composedLink = ApolloLink.from([purgeEdgesNodes, consoleLink, httpLink]);
// Create the apollo client
export default new ApolloClient({

View File

@ -39,29 +39,31 @@
}
}
// Result of edges/nodes removal
//
var purgedData = getRidOfEdges(data)
// debugger
if (!loading) {
const node = data.modules.edges[0].node;
this.module = {
...node,
objectiveGroups: mapNodes(node.objectivegroupSet, node => {
return {
...node,
objectives: mapNodes(node.objectiveSet, node => node)
};
}),
chapters: mapNodes(node.chapters, node => {
return {
...node,
contentBlocks: mapNodes(node.contentBlocks, node => node)
}
})
};
// Result of edges/nodes removal
//
const purgedData = getRidOfEdges(data)
this.module = purgedData.modules[0]
}
// if (!loading) {
// const node = data.modules.edges[0].node;
// this.module = {
// ...node,
// objectiveGroups: mapNodes(node.objectivegroupSet, node => {
// return {
// ...node,
// objectives: mapNodes(node.objectiveSet, node => node)
// };
// }),
// chapters: mapNodes(node.chapters, node => {
// return {
// ...node,
// contentBlocks: mapNodes(node.contentBlocks, node => node)
// }
// })
// };
// }
}
}
},