2019-10-09 20:26:37 +11:00

29 lines
644 B
JavaScript

import { useApolloClient, useMutation } from '@apollo/react-hooks'
import gql from 'graphql-tag'
const SINGLE_UPLOAD_MUTATION = gql`
mutation singleUpload($file: Upload!) {
singleUpload(file: $file) {
id
}
}
`
export const UploadFile = () => {
const [uploadFileMutation] = useMutation(SINGLE_UPLOAD_MUTATION)
const apolloClient = useApolloClient()
const onChange = ({
target: {
validity,
files: [file]
}
}) =>
validity.valid &&
uploadFileMutation({ variables: { file } }).then(() => {
apolloClient.resetStore()
})
return <input type="file" required onChange={onChange} />
}