Merge branch 'rethinkdb' into multi-file-upload
This commit is contained in:
commit
6aeaa0db64
@ -2,3 +2,8 @@ import path from 'path'
|
||||
|
||||
export const distPath = path.resolve(__dirname, 'dist')
|
||||
export const apiEndpoint = '/graphql'
|
||||
export const rethinkdb = {
|
||||
host: 'localhost',
|
||||
port: 28015,
|
||||
db: 'test'
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
"koa-bodyparser": "^4.2.0",
|
||||
"koa-compress": "^2.0.0",
|
||||
"koa-router": "^7.1.1",
|
||||
"rethinkdbdash": "^2.3.28",
|
||||
"source-map-support": "^0.4.14",
|
||||
"webpack": "^2.3.2",
|
||||
"zoo": "^0.1.9"
|
||||
|
||||
@ -1,17 +1,31 @@
|
||||
import getRethinkDB from './rethinkdb'
|
||||
|
||||
const getNewVal = (result) => {
|
||||
if (result.changes.length === 1) {
|
||||
return result.changes[0].new_val
|
||||
}
|
||||
return result.changes.map((file) => file.new_val)
|
||||
}
|
||||
|
||||
export default {
|
||||
Query: {
|
||||
ignore () {
|
||||
return null
|
||||
async allUploads () {
|
||||
const db = getRethinkDB()
|
||||
return await db.table('uploads')
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
singleUpload (root, {file}) {
|
||||
console.log('Uploaded file:', file)
|
||||
return file
|
||||
async singleUpload (_, {file}) {
|
||||
const db = getRethinkDB()
|
||||
const result = await db.table('uploads')
|
||||
.insert(file, {returnChanges: true})
|
||||
return getNewVal(result)
|
||||
},
|
||||
multiUpload (root, {files}) {
|
||||
console.log('Uploaded files:', files)
|
||||
return files
|
||||
async multiUpload (_, {files}) {
|
||||
const db = getRethinkDB()
|
||||
const result = await db.table('uploads')
|
||||
.insert(files, {returnChanges: true})
|
||||
return getNewVal(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
api/rethinkdb.js
Normal file
10
api/rethinkdb.js
Normal file
@ -0,0 +1,10 @@
|
||||
import rethinkdbdash from 'rethinkdbdash'
|
||||
import {rethinkdb} from './config'
|
||||
|
||||
let driver
|
||||
export default () => {
|
||||
if (!driver) {
|
||||
driver = rethinkdbdash(rethinkdb)
|
||||
}
|
||||
return driver
|
||||
}
|
||||
@ -13,8 +13,7 @@ input Upload {
|
||||
}
|
||||
|
||||
type Query {
|
||||
# GraphQL will not work without defining a query.
|
||||
ignore: Boolean
|
||||
allUploads: [File]
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user