Skip to content

Instantly share code, notes, and snippets.

@martinseanhunt
Created October 23, 2018 01:00
Show Gist options
  • Save martinseanhunt/856105543a9ed15129896e0a6fb08313 to your computer and use it in GitHub Desktop.
Save martinseanhunt/856105543a9ed15129896e0a6fb08313 to your computer and use it in GitHub Desktop.
<Mutation
mutation={CREATE_LIST_ITEM}
variables={{ title: this.state.title }}
// Refetch pagination data on creating an item to update item
// & page counts. The Query is being imported from ./Pagination
refetchQueries={[{ query: LIST_ITEMS_CONNECTION_QUERY }]}
// Call our helper function on update (it will be passed the chache)
update={deleteListItemsFromCache}
onCompleted={() => Router.push('/') }
>
{(createListItem, {error, loading}) => {
if(loading) return <p>Loading...</p>
if(error) return alert(error)
return (
<>
<label htmlFor="title">
Title:
<input
id="title"
name="title"
onChange={e => this.setState({ title: e.target.value })}
/>
</label>
<button onClick={createListItem}>Create Item</button>
</>
)
}}
</Mutation>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment