Skip to content

Instantly share code, notes, and snippets.

@unicodeveloper
Last active November 30, 2019 10:59
Show Gist options
  • Save unicodeveloper/c75cc8a9e9b3eee68d3c437f03763c4c to your computer and use it in GitHub Desktop.
Save unicodeveloper/c75cc8a9e9b3eee68d3c437f03763c4c to your computer and use it in GitHub Desktop.
Single file upload
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>
);
};
@newordn
Copy link

newordn commented Nov 30, 2019

Please can i have an example for multiple file uploads?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment