Handle IgnoreUser mutation errors

We now check if the IgnoreUser mutation returned an error before
updating the apollo store. If the mutation returns an error we keep
the store as it is, otherwise the user is added to the ignore list.
This commit is contained in:
Daniel Janeiro
2017-10-07 22:44:23 +01:00
parent 7eaad1541b
commit efdf7a6b25
@@ -3,6 +3,7 @@ import IgnoreUserConfirmation from './containers/IgnoreUserConfirmation';
import IgnoredUserSection from './containers/IgnoredUserSection';
import translations from './translations.yml';
import update from 'immutability-helper';
import get from 'lodash/get';
export default {
slots: {
@@ -14,7 +15,11 @@ export default {
mutations: {
IgnoreUser: ({variables}) => ({
updateQueries: {
CoralEmbedStream_Embed: (previousData) => {
CoralEmbedStream_Embed: (previousData, {mutationResult: {data: {ignoreUser}}}) => {
if (get(ignoreUser, 'errors.length')) {
return previousData;
}
const ignoredUserId = variables.id;
const updated = update(previousData, {me: {ignoredUsers: {$push: [{
id: ignoredUserId,