Add workaround for cache misses
This commit is contained in:
parent
3416465f8a
commit
daa8491578
|
|
@ -57,14 +57,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
update(store, {data: {deleteRoom: {success}}}) {
|
update(store, {data: {deleteRoom: {success}}}) {
|
||||||
try {
|
if (success) {
|
||||||
if (success) {
|
const data = store.readQuery({query: ROOMS_QUERY});
|
||||||
const data = store.readQuery({query: ROOMS_QUERY});
|
if (data) {
|
||||||
data.rooms.edges.splice(data.rooms.edges.findIndex(edge => edge.node.id === id), 1);
|
data.rooms.edges.splice(data.rooms.edges.findIndex(edge => edge.node.id === id), 1);
|
||||||
store.writeQuery({query: ROOMS_QUERY, data});
|
store.writeQuery({query: ROOMS_QUERY, data});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
// Query did not exist in the cache, and apollo throws a generic Error. Do nothing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,18 @@ const cache = new InMemoryCache({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: Monkey-patching in a fix for an open issue suggesting that
|
||||||
|
// `readQuery` should return null or undefined if the query is not yet in the
|
||||||
|
// cache: https://github.com/apollographql/apollo-feature-requests/issues/1
|
||||||
|
cache.originalReadQuery = cache.readQuery;
|
||||||
|
cache.readQuery = (...args) => {
|
||||||
|
try {
|
||||||
|
return cache.originalReadQuery(...args);
|
||||||
|
} catch (err) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Create the apollo client
|
// Create the apollo client
|
||||||
export default new ApolloClient({
|
export default new ApolloClient({
|
||||||
link: composedLink,
|
link: composedLink,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue