upload-apollo-client/app/components/single-uploader.js
Jayden Seric 5a935b6765 Renamed “client” “app” for clarity.
It was not intuitive that the “client” contained a client and server.
2017-04-04 02:49:18 +10:00

32 lines
676 B
JavaScript

import {Component} from 'react'
import {graphql, gql} from 'react-apollo'
class SingleUploader extends Component {
handleChange = ({target}) => {
if (target.validity.valid) {
this.props
.mutate({
variables: {
file: target.files[0]
}
})
.then(({data}) => console.log('Mutation response:', data))
}
}
render () {
return <input type='file' accept={'image/jpeg,image/png'} required onChange={this.handleChange} />
}
}
export default graphql(gql`
mutation singleUpload ($file: Upload!) {
singleUpload (file: $file) {
name
type
size
path
}
}
`)(SingleUploader)