Last active
November 30, 2019 10:59
-
-
Save unicodeveloper/c75cc8a9e9b3eee68d3c437f03763c4c to your computer and use it in GitHub Desktop.
Single file upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gql from 'graphql-tag' | |
import { Mutation } from 'react-apollo' | |
export const UPLOAD_FILE = gql` | |
mutation uploadFile($file: Upload!) { | |
uploadFile(file: $file) { | |
filename | |
} | |
} | |
`; | |
const uploadOneFile = () => { | |
return ( | |
<Mutation mutation={UPLOAD_FILE}> | |
{uploadFile => ( | |
<input | |
type="file" | |
required | |
onChange={({ target: { validity, files: [file] } }) => | |
validity.valid && uploadFile({ variables: { file } }); | |
} | |
/> | |
)} | |
</Mutation> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please can i have an example for multiple file uploads?