Last active
April 28, 2020 15:16
-
-
Save epalaz/92f0048573b27462f765785f1d60129b to your computer and use it in GitHub Desktop.
Resolvers for File Upload Mutations
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
const resolvers = { | |
Mutation: { | |
singleUpload: (parent, args) => { | |
return args.file.then(file => { | |
const {createReadStream, filename, mimetype} = file | |
const fileStream = createReadStream() | |
fileStream.pipe(fs.createWriteStream(`./uploadedFiles/${filename}`)) | |
return file; | |
}); | |
}, | |
singleUploadStream: async (parent, args) => { | |
const file = await args.file | |
const {createReadStream, filename, mimetype} = file | |
const fileStream = createReadStream() | |
//Here stream it to S3 | |
// Enter your bucket name here next to "Bucket: " | |
const uploadParams = {Bucket: 'apollo-file-upload-test', Key: filename, Body: fileStream}; | |
const result = await s3.upload(uploadParams).promise() | |
console.log(result) | |
return file; | |
} | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment