Files
talk/plugins/talk-plugin-notifications/client/graphql.js
T
2018-06-05 04:28:54 +02:00

53 lines
1.2 KiB
JavaScript

import { gql } from 'react-apollo';
export default {
fragments: {
UpdateNotificationSettingsResponse: gql`
fragment Talk_UpdateNotificationSettingsResponse on UpdateNotificationSettingsResponse {
errors {
translation_key
}
}
`,
},
mutations: {
UpdateNotificationSettings: ({
variables: { input },
state: {
auth: {
user: { id },
},
},
}) => ({
optimisticResponse: {
updateNotificationSettings: {
__typename: 'UpdateNotificationSettingsResponse',
errors: null,
},
},
update: proxy => {
if (input.digestFrequency === undefined) {
return;
}
const fragment = gql`
fragment TalkNotificationsCategoryReply_User_Fragment on User {
notificationSettings {
digestFrequency
}
}
`;
const fragmentId = `User_${id}`;
const data = {
__typename: 'User',
notificationSettings: {
__typename: 'NotificationSettings',
digestFrequency: input.digestFrequency,
},
};
proxy.writeFragment({ fragment, id: fragmentId, data });
},
}),
},
};