New linting for the API.
This commit is contained in:
parent
0e7723a00e
commit
409d1919c9
783
api/package-lock.json
generated
783
api/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -23,11 +23,15 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-eslint": "^7.2.3",
|
"babel-eslint": "^7.2.3",
|
||||||
"standard": "^10.0.2",
|
"eslint": "^4.1.1",
|
||||||
|
"eslint-plugin-import": "^2.7.0",
|
||||||
|
"eslint-plugin-node": "^5.1.0",
|
||||||
|
"eslint-plugin-prettier": "^2.1.2",
|
||||||
|
"prettier": "^1.5.2",
|
||||||
"webpack-watch-server": "^1.0.0"
|
"webpack-watch-server": "^1.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "standard",
|
"lint": "eslint .",
|
||||||
"dev": "zoo webpack-watch-server",
|
"dev": "zoo webpack-watch-server",
|
||||||
"build": "zoo webpack",
|
"build": "zoo webpack",
|
||||||
"start": "zoo node dist"
|
"start": "zoo node dist"
|
||||||
@ -49,10 +53,39 @@
|
|||||||
"stage-0"
|
"stage-0"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"standard": {
|
"eslintConfig": {
|
||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
"ignore": [
|
"parserOptions": {
|
||||||
"dist/**"
|
"sourceType": "module",
|
||||||
]
|
"ecmaVersion": 2017,
|
||||||
}
|
"ecmaFeatures": {
|
||||||
|
"experimentalObjectRestSpread": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"es6": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:import/recommended",
|
||||||
|
"plugin:node/recommended"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"import",
|
||||||
|
"node",
|
||||||
|
"prettier"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"node/no-unsupported-features": "off",
|
||||||
|
"prettier/prettier": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"eslintIgnore": ["dist"]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,12 +5,15 @@ const db = low('db.json', {
|
|||||||
storage
|
storage
|
||||||
})
|
})
|
||||||
|
|
||||||
db.defaults({
|
db
|
||||||
uploads: []
|
.defaults({
|
||||||
}).write()
|
uploads: []
|
||||||
|
})
|
||||||
|
.write()
|
||||||
|
|
||||||
const saveFile = file => {
|
const saveFile = file => {
|
||||||
return db.get('uploads')
|
return db
|
||||||
|
.get('uploads')
|
||||||
.push({
|
.push({
|
||||||
id: file.path,
|
id: file.path,
|
||||||
...file
|
...file
|
||||||
@ -22,14 +25,16 @@ const saveFile = file => {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
uploads () {
|
uploads() {
|
||||||
return db.get('uploads').value()
|
return db.get('uploads').value()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
singleUpload: (_, {file}) => saveFile(file),
|
singleUpload: (_, { file }) => saveFile(file),
|
||||||
multipleUpload (_, {files}) {
|
multipleUpload(_, { files }) {
|
||||||
return Promise.all(files.map(file => saveFile(file))).then(results => results)
|
return Promise.all(files.map(file => saveFile(file))).then(
|
||||||
|
results => results
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,41 +4,37 @@ import cors from 'kcors'
|
|||||||
import compress from 'koa-compress'
|
import compress from 'koa-compress'
|
||||||
import KoaRouter from 'koa-router'
|
import KoaRouter from 'koa-router'
|
||||||
import koaBody from 'koa-bodyparser'
|
import koaBody from 'koa-bodyparser'
|
||||||
import {makeExecutableSchema} from 'graphql-tools'
|
import { makeExecutableSchema } from 'graphql-tools'
|
||||||
import {graphqlKoa} from 'graphql-server-koa'
|
import { graphqlKoa } from 'graphql-server-koa'
|
||||||
import {apolloUploadKoa} from 'apollo-upload-server'
|
import { apolloUploadKoa } from 'apollo-upload-server'
|
||||||
import typeDefs from './schema.graphql'
|
import typeDefs from './schema.graphql'
|
||||||
import resolvers from './resolvers'
|
import resolvers from './resolvers'
|
||||||
|
|
||||||
const app = new Koa()
|
const app = new Koa()
|
||||||
const router = new KoaRouter()
|
const router = new KoaRouter()
|
||||||
const schema = makeExecutableSchema({
|
const schema = makeExecutableSchema({ typeDefs, resolvers })
|
||||||
typeDefs,
|
|
||||||
resolvers
|
|
||||||
})
|
|
||||||
|
|
||||||
// Enable Cross-Origin Resource Sharing (CORS)
|
app
|
||||||
app.use(cors())
|
// Enable Cross-Origin Resource Sharing (CORS)
|
||||||
|
.use(cors())
|
||||||
// Enable gzip
|
// Enable gzip
|
||||||
app.use(compress())
|
.use(compress())
|
||||||
|
// Parse body
|
||||||
// Parse body
|
.use(koaBody())
|
||||||
app.use(koaBody())
|
|
||||||
|
|
||||||
// GraphQL API
|
// GraphQL API
|
||||||
router.post(
|
router.post(
|
||||||
'/graphql',
|
'/graphql',
|
||||||
apolloUploadKoa({
|
apolloUploadKoa({ uploadDir: '/tmp/apollo-upload-examples' }),
|
||||||
uploadDir: '/tmp/apollo-upload-examples'
|
graphqlKoa({ schema })
|
||||||
}),
|
|
||||||
graphqlKoa({
|
|
||||||
schema
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
app.use(router.routes())
|
app.use(router.routes()).use(router.allowedMethods())
|
||||||
app.use(router.allowedMethods())
|
|
||||||
|
|
||||||
app.listen(process.env.PORT)
|
app.listen(process.env.PORT)
|
||||||
console.log(`Serving at http://localhost:${process.env.PORT} in ${process.env.NODE_ENV} mode.`)
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.info(
|
||||||
|
`Serving at http://localhost:${process.env.PORT} in ${process.env
|
||||||
|
.NODE_ENV} mode.`
|
||||||
|
)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import {NoEmitOnErrorsPlugin} from 'webpack'
|
import { NoEmitOnErrorsPlugin } from 'webpack'
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
devtool: 'source-map',
|
devtool: 'source-map',
|
||||||
@ -17,27 +17,28 @@ const config = {
|
|||||||
__dirname: true
|
__dirname: true
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [{
|
rules: [
|
||||||
test: /\.js$/,
|
{
|
||||||
exclude: /node_modules/,
|
test: /\.js$/,
|
||||||
use: {
|
exclude: /node_modules/,
|
||||||
loader: 'babel-loader',
|
use: {
|
||||||
options: {
|
loader: 'babel-loader',
|
||||||
cacheDirectory: process.env.NODE_ENV === 'development'
|
options: {
|
||||||
|
cacheDirectory: process.env.NODE_ENV === 'development'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.(graphql|gql)$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
loader: 'graphql-tag/loader'
|
||||||
}
|
}
|
||||||
}, {
|
]
|
||||||
test: /\.(graphql|gql)$/,
|
|
||||||
exclude: /node_modules/,
|
|
||||||
loader: 'graphql-tag/loader'
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
config.plugins = [
|
config.plugins = [new NoEmitOnErrorsPlugin()]
|
||||||
new NoEmitOnErrorsPlugin()
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default config
|
export default config
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user