Created
January 26, 2019 00:04
-
-
Save scottdomes/67c0f64b5fabccf7ef8e266c28741555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
name | |
} | |
} | |
} | |
} | |
`; | |
function commit(name, email, viewer) { | |
return commitMutation(environment, { | |
mutation, | |
variables: { | |
input: { | |
name, | |
} | |
}, | |
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