Skip to content

Commit

Permalink
Fix - Récupération des legals après modif de don
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreymugnier committed Nov 9, 2020
1 parent 5c60390 commit 7d3bf63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/routes/cart/CartCheckout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
legalId = res.data.id;
isSavingLegals = false;
++step;
graphQLInstance.clearApolloCache(res.data.id);
};
</script>

Expand Down
34 changes: 22 additions & 12 deletions src/services/SheaftGraphQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,31 @@ class SheaftGraphQL {

clearApolloCache(typename) {
if (!typename) return;

var type = this.findDataType(typename)[0];
if (!type) return;

if (!client.cache.data.data.ROOT_QUERY) return;

var cacheUpdated = false;
var props = Object.getOwnPropertyNames(client.cache.data.data.ROOT_QUERY);
for (var i = 0; i < props.length; i++) {
if (props[i] == type || props[i].indexOf(type + "(") > -1) {
var queries = Object.getOwnPropertyNames(client.cache.data.data);
for (var j = 0; j < queries.length; j++) {
if (queries[j].indexOf("$ROOT_QUERY." + props[i]) > -1) {
client.cache.data.delete(queries[j]);
cacheUpdated = true;
const props = Object.getOwnPropertyNames(client.cache.data.data.ROOT_QUERY);
const queries = Object.getOwnPropertyNames(client.cache.data.data);

// on a passé un id, traitement spécifique
if (typeof typename == "string") {
const query = queries.find((q) => q == typename);
if (query) {
client.cache.data.delete(query);
cacheUpdated = true;
}
} else {
var type = this.findDataType(typename)[0];

if (!type) return;

for (var i = 0; i < props.length; i++) {
if (props[i] == type || props[i].indexOf(type + "(") > -1) {
for (var j = 0; j < queries.length; j++) {
if (queries[j].indexOf("$ROOT_QUERY." + props[i]) > -1) {
client.cache.data.delete(queries[j]);
cacheUpdated = true;
}
}
}
}
Expand Down

0 comments on commit 7d3bf63

Please sign in to comment.