Add rethinkdb

This commit is contained in:
Michael Merrill 2017-04-03 20:16:27 -06:00
parent 54b686fda3
commit 14be2c2433
4 changed files with 35 additions and 6 deletions

View File

@ -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'
}

View File

@ -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"

View File

@ -1,3 +1,12 @@
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 () {
@ -5,13 +14,17 @@ export default {
}
},
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
View File

@ -0,0 +1,10 @@
import rethinkdbdash from 'rethinkdbdash'
import {rethinkdb} from './config'
let driver
export default () => {
if (!driver) {
driver = rethinkdbdash(rethinkdb)
}
return driver
}