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 distPath = path.resolve(__dirname, 'dist')
export const apiEndpoint = '/graphql' 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-bodyparser": "^4.2.0",
"koa-compress": "^2.0.0", "koa-compress": "^2.0.0",
"koa-router": "^7.1.1", "koa-router": "^7.1.1",
"rethinkdbdash": "^2.3.28",
"source-map-support": "^0.4.14", "source-map-support": "^0.4.14",
"webpack": "^2.3.2", "webpack": "^2.3.2",
"zoo": "^0.1.9" "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 { export default {
Query: { Query: {
ignore () { async allUploads () {
return null const db = getRethinkDB()
return await db.table('uploads')
} }
}, },
Mutation: { Mutation: {
singleUpload (root, {file}) { async singleUpload (_, {file}) {
console.log('Uploaded file:', file) const db = getRethinkDB()
return file const result = await db.table('uploads')
.insert(file, {returnChanges: true})
return getNewVal(result)
}, },
multiUpload (root, {files}) { async multiUpload (_, {files}) {
console.log('Uploaded files:', files) const db = getRethinkDB()
return files 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 { type Query {
# GraphQL will not work without defining a query. allUploads: [File]
ignore: Boolean
} }
type Mutation { type Mutation {