Merge branch 'rethinkdb' into multi-file-upload

This commit is contained in:
Michael Merrill 2017-04-03 21:04:51 -06:00
commit 6aeaa0db64
5 changed files with 39 additions and 10 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,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
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
}

View File

@ -13,8 +13,7 @@ input Upload {
}
type Query {
# GraphQL will not work without defining a query.
ignore: Boolean
allUploads: [File]
}
type Mutation {