mirror of
https://github.com/wassname/talk.git
synced 2026-07-28 11:27:05 +08:00
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
import { gql } from 'react-apollo';
|
|
import update from 'immutability-helper';
|
|
import withMutation from 'coral-framework/hocs/withMutation';
|
|
|
|
export const withUpdateEmailAddress = withMutation(
|
|
gql`
|
|
mutation UpdateEmailAddress($input: UpdateEmailAddressInput!) {
|
|
updateEmailAddress(input: $input) {
|
|
...UpdateEmailAddressResponse
|
|
}
|
|
}
|
|
`,
|
|
{
|
|
props: ({ mutate }) => ({
|
|
updateEmailAddress: input => {
|
|
return mutate({
|
|
variables: {
|
|
input,
|
|
},
|
|
update: proxy => {
|
|
const UpdateEmailAddressQuery = gql`
|
|
query Talk_UpdateEmailAddress {
|
|
me {
|
|
id
|
|
email
|
|
}
|
|
}
|
|
`;
|
|
|
|
const prev = proxy.readQuery({ query: UpdateEmailAddressQuery });
|
|
|
|
const data = update(prev, {
|
|
me: {
|
|
email: { $set: input.email },
|
|
},
|
|
});
|
|
|
|
proxy.writeQuery({
|
|
query: UpdateEmailAddressQuery,
|
|
data,
|
|
});
|
|
},
|
|
});
|
|
},
|
|
}),
|
|
}
|
|
);
|