Smarter cache updates on mutation responses.
This commit is contained in:
parent
a7cf818e15
commit
2951ad3434
@ -7,14 +7,12 @@ const MultipleUploader = ({ mutate }) => {
|
||||
const handleChange = ({ target }) =>
|
||||
target.validity.valid &&
|
||||
mutate({
|
||||
variables: {
|
||||
files: target.files
|
||||
},
|
||||
refetchQueries: [
|
||||
{
|
||||
query: uploadsQuery
|
||||
}
|
||||
]
|
||||
variables: { files: target.files },
|
||||
update: (proxy, { data: { multipleUpload } }) => {
|
||||
const data = proxy.readQuery({ query: uploadsQuery })
|
||||
data.uploads.push(...multipleUpload)
|
||||
proxy.writeQuery({ query: uploadsQuery, data })
|
||||
}
|
||||
})
|
||||
|
||||
return <FileInput multiple required onChange={handleChange} />
|
||||
|
||||
@ -7,14 +7,12 @@ const SingleUploader = ({ mutate }) => {
|
||||
const handleChange = ({ target }) =>
|
||||
target.validity.valid &&
|
||||
mutate({
|
||||
variables: {
|
||||
file: target.files[0]
|
||||
},
|
||||
refetchQueries: [
|
||||
{
|
||||
query: uploadsQuery
|
||||
}
|
||||
]
|
||||
variables: { file: target.files[0] },
|
||||
update: (proxy, { data: { singleUpload } }) => {
|
||||
const data = proxy.readQuery({ query: uploadsQuery })
|
||||
data.uploads.push(singleUpload)
|
||||
proxy.writeQuery({ query: uploadsQuery, data })
|
||||
}
|
||||
})
|
||||
|
||||
return <FileInput required onChange={handleChange} />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user