Skip to content

Instantly share code, notes, and snippets.

@scottdomes
Created January 26, 2019 00:04
Show Gist options
  • Save scottdomes/67c0f64b5fabccf7ef8e266c28741555 to your computer and use it in GitHub Desktop.
Save scottdomes/67c0f64b5fabccf7ef8e266c28741555 to your computer and use it in GitHub Desktop.
import React from 'react';
import Form from '../components/Form';
import { commitMutation } from 'react-relay';
import graphql from 'babel-plugin-relay/macro';
import environment from './environment';
import updateLocalStore from './updateLocalStore';
const mutation = graphql`
mutation MutationComponentMutation($input: ContactInput!) {
createContact(input: $input) {
contactEdge {
node {
id
email
name
}
}
}
}
`;
function commit(name, email, viewer) {
return commitMutation(environment, {
mutation,
variables: {
input: {
name,
email
}
},
updater: (store, data) => updateLocalStore(store, data, viewer)
});
}
const MutationComponent = ({ viewer }) => {
return (
<Form
onSubmit={(name, email) => {
commit(name, email, viewer);
}}
/>
);
};
export default MutationComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment