Jayden Seric c789b3738b Updated dependencies and configs.
- Updated dependencies.
- Using a Next.js plugin for bundle analysis.
- Updated ESLint config.
- Removed npm from package engines.
- Using cross-fetch in place of isomorphic-unfetch.
2018-04-25 13:19:27 +10:00

36 lines
780 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
encoding
mimetype
path
}
}
`)(UploadFile)