upload-apollo-client/api/resolvers.js
Jayden Seric 6492ba8fef Componentization improvements.
- Using a new component for sections.
- Renamed “multi” to “multiple” in the uploader name, to match the input attribute “multiple”.
2017-04-09 13:13:39 +10:00

36 lines
675 B
JavaScript

import low from 'lowdb'
import fileAsync from 'lowdb/lib/storages/file-async'
// Start database using file-async storage
const db = low('db.json', {
storage: fileAsync
})
db.defaults({uploads: []})
.write()
const saveFile = file => {
return db.get('uploads')
.push(file)
.last()
.write()
.then(result => result)
}
export default {
Query: {
allUploads () {
return db.get('uploads').value()
}
},
Mutation: {
singleUpload (_, {file}) {
return saveFile(file)
},
multipleUpload (_, {files}) {
return Promise.all(files.map((file) => {
return saveFile(file)
})).then(results => results)
}
}
}