Added Blob type example

This commit is contained in:
Sam Coenen 2018-01-25 15:31:41 +01:00
parent a5f677a377
commit b977d14385
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,35 @@
import { graphql } from 'react-apollo'
import gql from 'graphql-tag'
import FileInput from './file-input'
import uploadsQuery from '../queries/uploads'
const BlobUploader = ({ mutate }) => {
const handleChange = ({ target }) => {
// We just convert the actual File to a Blob for the example
const blob = new Blob([target.files[0].slice(0, -1)], { type: target.files[0].type })
blob.name = target.files[0].name; // Don't forget to add the name to the Blob or it will be unnamed!
mutate({
variables: { file: blob },
update: (proxy, { data: { singleUpload } }) => {
const data = proxy.readQuery({ query: uploadsQuery })
data.uploads.push(singleUpload)
proxy.writeQuery({ query: uploadsQuery, data })
}
})
}
return <FileInput required onChange={handleChange} title={'Blob upload'} />
}
export default graphql(gql`
mutation($file: Upload!) {
singleUpload(file: $file) {
id
filename
encoding
mimetype
path
}
}
`)(BlobUploader)

View File

@ -1,6 +1,7 @@
import Page from '../components/page'
import SingleUploader from '../components/single-uploader'
import MultipleUploader from '../components/multiple-uploader'
import BlobUploader from '../components/blob-uploader'
import UploadList from '../components/upload-list'
import withData from '../providers/with-data'
@ -14,6 +15,7 @@ const HomePage = () => (
/>
<SingleUploader />
<MultipleUploader />
<BlobUploader />
<UploadList />
</Page>
)