mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge remote-tracking branch 'origin/master' into mochajs
This commit is contained in:
commit
71c4ffb012
10
README.md
10
README.md
@ -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
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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
23
src/seed/unseed-db.js
Normal 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)
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user