Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Commit 36e6883

Browse files
committed
docs: graphql schema stitching w neo4j-graphql-js
1 parent 2a8a8ad commit 36e6883

24 files changed

+16083
-0
lines changed

example/schema-stitching/.env.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
JWT_SECRET='supersecret'
2+
NEO4J_USERNAME='neo4j'
3+
NEO4J_PASSWORD='letmein'
4+
NEO4J_PROTOCOL=neo4j
5+
NEO4J_HOST=localhost
6+
NEO4J_DATABASE=neo4j
7+
NEO4J_ENCRYPTION=ENCRYPTION_OFF

example/schema-stitching/.eslintrc.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
plugins: ['jest'],
3+
env: {
4+
es6: true,
5+
node: true,
6+
'jest/globals': true
7+
},
8+
extends: 'airbnb-base',
9+
globals: {
10+
Atomics: 'readonly',
11+
SharedArrayBuffer: 'readonly'
12+
},
13+
parserOptions: {
14+
ecmaVersion: 2018,
15+
sourceType: 'module'
16+
},
17+
rules: {
18+
'jest/no-disabled-tests': 'warn',
19+
'jest/no-focused-tests': 'error',
20+
'jest/no-identical-title': 'error',
21+
'jest/prefer-to-have-length': 'warn',
22+
'jest/valid-expect': 'error',
23+
'import/no-extraneous-dependencies': [
24+
'error',
25+
{ devDependencies: ['db/**/*.js', '**/*.test.js', '**/*.spec.js'] }
26+
]
27+
}
28+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [['@babel/preset-env', { targets: { node: 'current' } }]]
3+
};

example/schema-stitching/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ApolloServer } from 'apollo-server';
2+
import Server from './src/server';
3+
4+
const playground = {
5+
settings: {
6+
'schema.polling.enable': false
7+
}
8+
};
9+
10+
(async () => {
11+
const server = await Server(ApolloServer, { playground });
12+
const { url } = await server.listen();
13+
// eslint-disable-next-line no-console
14+
console.log(`🚀 Server ready at ${url}`);
15+
})();

example/schema-stitching/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "neo4j-graphql-js-example-schema-stitching",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"scripts": {
7+
"lint": "eslint .",
8+
"test": "jest",
9+
"test:debug": "node inspect node_modules/jest/bin/jest.js",
10+
"dev": "nodemon -r esm index.js",
11+
"dev:debug": "nodemon inspect -r esm index.js",
12+
"db:seed": "node -r esm src/db/seed.js",
13+
"db:clean": "node -r esm src/db/clean.js"
14+
},
15+
"dependencies": {
16+
"@graphql-tools/delegate": "^7.0.7",
17+
"@graphql-tools/graphql-file-loader": "^6.2.6",
18+
"@graphql-tools/load": "^6.2.5",
19+
"@graphql-tools/schema": "^7.1.2",
20+
"@graphql-tools/stitch": "^7.1.4",
21+
"@graphql-tools/wrap": "^7.0.4",
22+
"apollo-datasource": "^0.7.2",
23+
"apollo-server": "^2.19.0",
24+
"bcrypt": "^5.0.0",
25+
"dotenv-flow": "^3.2.0",
26+
"graphql-tools": "^7.0.2",
27+
"jsonwebtoken": "^8.5.1",
28+
"neo4j-driver": "^4.2.1",
29+
"neo4j-graphql-js": "^2.17.1",
30+
"neode": "^0.4.6"
31+
},
32+
"devDependencies": {
33+
"@babel/core": "^7.12.9",
34+
"@babel/preset-env": "^7.12.7",
35+
"apollo-server-testing": "^2.19.0",
36+
"babel-eslint": "^10.1.0",
37+
"babel-jest": "^26.6.3",
38+
"eslint": "^7.14.0",
39+
"eslint-config-airbnb-base": "^14.2.1",
40+
"eslint-plugin-import": "^2.22.1",
41+
"eslint-plugin-jest": "^24.1.3",
42+
"esm": "^3.2.25",
43+
"jest": "^26.6.3",
44+
"nodemon": "^2.0.6"
45+
}
46+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require('dotenv-flow').config();
2+
3+
export const { JWT_SECRET, NEO4J_USERNAME, NEO4J_PASSWORD } = process.env;
4+
if (!(JWT_SECRET && NEO4J_USERNAME && NEO4J_PASSWORD)) {
5+
throw new Error(`
6+
7+
Please create a .env file and configure environment variables there.
8+
9+
You could e.g. copy the .env file used for testing:
10+
11+
$ cp .env.text .env
12+
`);
13+
}
14+
export default { JWT_SECRET, NEO4J_USERNAME, NEO4J_PASSWORD };
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import jwt from 'jsonwebtoken';
2+
import driver from './driver';
3+
import { JWT_SECRET } from './config';
4+
5+
export default function context({ req }) {
6+
let token = req.headers.authorization || '';
7+
token = token.replace('Bearer ', '');
8+
const jwtSign = payload => jwt.sign(payload, JWT_SECRET);
9+
try {
10+
const decoded = jwt.verify(token, JWT_SECRET);
11+
return { ...decoded, jwtSign, driver };
12+
} catch (e) {
13+
return { jwtSign, driver };
14+
}
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import neode from './neode';
2+
3+
(async () => {
4+
await neode.driver
5+
.session()
6+
.writeTransaction(txc => txc.run('MATCH(n) DETACH DELETE n;'));
7+
neode.driver.close();
8+
})();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import bcrypt from 'bcrypt';
2+
import neode from '../neode';
3+
4+
export default class Person {
5+
constructor(data) {
6+
Object.assign(this, data);
7+
}
8+
9+
checkPassword(password) {
10+
return bcrypt.compareSync(password, this.hashedPassword);
11+
}
12+
13+
async save() {
14+
this.hashedPassword = bcrypt.hashSync(this.password, 10);
15+
const node = await neode.create('Person', this);
16+
Object.assign(this, { ...node.properties(), node });
17+
return this;
18+
}
19+
20+
static async first(props) {
21+
const node = await neode.first('Person', props);
22+
if (!node) return null;
23+
return new Person({ ...node.properties(), node });
24+
}
25+
26+
static currentUser(context) {
27+
const { person } = context;
28+
if (!person) return null;
29+
return Person.first({ id: person.id });
30+
}
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import neode from '../neode';
2+
3+
export default class Post {
4+
constructor(data) {
5+
Object.assign(this, data);
6+
}
7+
8+
async save() {
9+
if (!(this.author && this.author.node))
10+
throw new Error('author node is missing!');
11+
const node = await neode.create('Post', this);
12+
await node.relateTo(this.author.node, 'wrote');
13+
Object.assign(this, { ...node.properties(), node });
14+
return this;
15+
}
16+
}

0 commit comments

Comments
 (0)