Jayden Seric 4d258cf0d5 Removed encoding from the File type.
It was missleading, as the encoding was only for the upload stream, not the file contents when stored.
2018-09-18 22:08:10 +10:00

40 lines
802 B
JavaScript

import { graphql } from 'react-apollo'
import gql from 'graphql-tag'
import uploadsQuery from '../queries/uploads'
const UploadFile = ({ mutate }) => {
const handleChange = ({
target: {
validity,
files: [file]
}
}) =>
validity.valid &&
mutate({
variables: { file },
update(
proxy,
{
data: { singleUpload }
}
) {
const data = proxy.readQuery({ query: uploadsQuery })
data.uploads.push(singleUpload)
proxy.writeQuery({ query: uploadsQuery, data })
}
})
return <input type="file" required onChange={handleChange} />
}
export default graphql(gql`
mutation($file: Upload!) {
singleUpload(file: $file) {
id
filename
mimetype
path
}
}
`)(UploadFile)