Merge remote-tracking branch 'origin/master' into mochajs

This commit is contained in:
Robert Schäfer 2018-12-04 21:35:45 +01:00
commit 71c4ffb012
5 changed files with 635 additions and 430 deletions

View File

@ -99,7 +99,7 @@ you build a frontend application without running a neo4j instance.
Just set `MOCK=true` inside `.env` or pass it on application start.
## Seeding The Database
## Seeding and Cleaning The Database
Optionally you can seed the GraphQL service by executing mutations that
will write sample data to the database:
@ -110,6 +110,14 @@ yarn run db:seed
npm run db:seed
```
For a reset you can use the reset script:
```bash
yarn db:reset
# -or-
npm run db:reset
```
## Run Tests
```bash
yarn run test

View File

@ -7,9 +7,10 @@
"test": "mocha --require @babel/register src/**/*.test.js",
"start": "./node_modules/.bin/nodemon --exec babel-node src/index.js",
"start:debug": "./node_modules/.bin/nodemon --exec babel-node --inspect=0.0.0.0:9229 src/index.js",
"db:seed": "concurrently --kill-others --success first 'cross-env GRAPHQL_URI=http://localhost:4001 PERMISSIONS=disabled GRAPHQL_PORT=4001 yarn run start' 'wait-on tcp:4001 && cross-env GRAPHQL_URI=http://localhost:4001 ./node_modules/.bin/babel-node src/seed/seed-db.js'"
"db:seed": "concurrently --kill-others --success first 'cross-env GRAPHQL_URI=http://localhost:4001 PERMISSIONS=disabled GRAPHQL_PORT=4001 yarn run start' 'wait-on tcp:4001 && cross-env GRAPHQL_URI=http://localhost:4001 ./node_modules/.bin/babel-node src/seed/seed-db.js'",
"db:reset": "concurrently --kill-others --success first 'cross-env GRAPHQL_URI=http://localhost:4001 PERMISSIONS=disabled GRAPHQL_PORT=4001 yarn run start' 'wait-on tcp:4001 && cross-env GRAPHQL_URI=http://localhost:4001 ./node_modules/.bin/babel-node src/seed/unseed-db.js'"
},
"author": "Human Connection gGmbh",
"author": "Human Connection gGmbH",
"license": "MIT",
"dependencies": {
"@babel/cli": "^7.1.5",
@ -17,7 +18,6 @@
"@babel/node": "^7.0.0",
"@babel/preset-env": "^7.1.6",
"@babel/register": "^7.0.0",
"apollo-boost": "^0.1.10",
"apollo-cache-inmemory": "^1.2.5",
"apollo-client": "^2.3.2",
"apollo-link-http": "^1.5.4",

View File

@ -10,7 +10,7 @@ export const typeDefs =
fs.readFileSync(process.env.GRAPHQL_SCHEMA || path.join(__dirname, "schema.graphql"))
.toString('utf-8')
const query = (cypher, session) => {
export const query = (cypher, session) => {
return new Promise((resolve, reject) => {
let data = []
session

23
src/seed/unseed-db.js Normal file
View File

@ -0,0 +1,23 @@
import { query } from '../graphql-schema'
import dotenv from 'dotenv'
import neo4j from '../bootstrap/neo4j'
dotenv.config()
if (process.env.NODE_ENV === 'production') {
throw new Error('YOU CAN`T UNSEED IN PRODUCTION MODE')
}
const driver = neo4j().getDriver()
const session = driver.session()
query('MATCH (n) DETACH DELETE n', session).then(() => {
console.log('Successfully deleted all nodes and relations!')
}).catch((err) => {
console.log(`Error occurred deleting the nodes and relations (reset the db)\n\n${err}`)
}).finally(() => {
if (session) {
session.close()
}
process.exit(0)
})

1024
yarn.lock

File diff suppressed because it is too large Load Diff