Smarter cache updates on mutation responses.

This commit is contained in:
Jayden Seric 2017-11-20 00:31:02 +11:00
parent a7cf818e15
commit 2951ad3434
2 changed files with 12 additions and 16 deletions

View File

@ -7,14 +7,12 @@ const MultipleUploader = ({ mutate }) => {
const handleChange = ({ target }) => const handleChange = ({ target }) =>
target.validity.valid && target.validity.valid &&
mutate({ mutate({
variables: { variables: { files: target.files },
files: target.files update: (proxy, { data: { multipleUpload } }) => {
}, const data = proxy.readQuery({ query: uploadsQuery })
refetchQueries: [ data.uploads.push(...multipleUpload)
{ proxy.writeQuery({ query: uploadsQuery, data })
query: uploadsQuery }
}
]
}) })
return <FileInput multiple required onChange={handleChange} /> return <FileInput multiple required onChange={handleChange} />

View File

@ -7,14 +7,12 @@ const SingleUploader = ({ mutate }) => {
const handleChange = ({ target }) => const handleChange = ({ target }) =>
target.validity.valid && target.validity.valid &&
mutate({ mutate({
variables: { variables: { file: target.files[0] },
file: target.files[0] update: (proxy, { data: { singleUpload } }) => {
}, const data = proxy.readQuery({ query: uploadsQuery })
refetchQueries: [ data.uploads.push(singleUpload)
{ proxy.writeQuery({ query: uploadsQuery, data })
query: uploadsQuery }
}
]
}) })
return <FileInput required onChange={handleChange} /> return <FileInput required onChange={handleChange} />