33 lines
628 B
JavaScript
33 lines
628 B
JavaScript
import { graphql, gql } from 'react-apollo'
|
|
import FileInput from './file-input'
|
|
import uploadsQuery from '../queries/uploads'
|
|
|
|
const SingleUploader = ({ mutate }) => {
|
|
const handleChange = ({ target }) =>
|
|
target.validity.valid &&
|
|
mutate({
|
|
variables: {
|
|
file: target.files[0]
|
|
},
|
|
refetchQueries: [
|
|
{
|
|
query: uploadsQuery
|
|
}
|
|
]
|
|
})
|
|
|
|
return <FileInput required onChange={handleChange} />
|
|
}
|
|
|
|
export default graphql(gql`
|
|
mutation($file: Upload!) {
|
|
singleUpload(file: $file) {
|
|
id
|
|
name
|
|
type
|
|
size
|
|
path
|
|
}
|
|
}
|
|
`)(SingleUploader)
|