@rxdi/neo4j 0.7.153 → 0.7.154
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -19
- package/dist/injection.tokens.d.ts +10 -22
- package/dist/injection.tokens.js +17 -2
- package/dist/{services/util.service.d.ts → neo4j.service.d.ts} +4 -3
- package/dist/{services/util.service.js → neo4j.service.js} +43 -31
- package/package.json +68 -68
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.js +0 -13
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -30,31 +30,22 @@ exports.Neo4JModule = void 0;
|
|
|
30
30
|
const core_1 = require("@rxdi/core");
|
|
31
31
|
const injection_tokens_1 = require("./injection.tokens");
|
|
32
32
|
const graphql_1 = require("@rxdi/graphql");
|
|
33
|
-
const
|
|
33
|
+
const neo4j_service_1 = require("./neo4j.service");
|
|
34
34
|
let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
|
|
35
35
|
static forRoot(config = {}) {
|
|
36
36
|
return {
|
|
37
37
|
module: Neo4JModule_1,
|
|
38
38
|
providers: [
|
|
39
|
+
neo4j_service_1.UtilService,
|
|
39
40
|
{
|
|
40
41
|
provide: injection_tokens_1.NEO4J_MODULE_CONFIG,
|
|
41
42
|
useValue: config
|
|
42
43
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
useFactory: (config) => config.onRequest
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
: [
|
|
52
|
-
{
|
|
53
|
-
provide: injection_tokens_1.NEO4J_DRIVER,
|
|
54
|
-
deps: [util_service_1.UtilService],
|
|
55
|
-
useFactory: (util) => util.assignDriverToContext()
|
|
56
|
-
}
|
|
57
|
-
]),
|
|
44
|
+
{
|
|
45
|
+
provide: injection_tokens_1.NEO4J_DRIVER,
|
|
46
|
+
deps: [neo4j_service_1.UtilService],
|
|
47
|
+
useFactory: (util) => util.createDriver()
|
|
48
|
+
},
|
|
58
49
|
...(config.schemaOverride
|
|
59
50
|
? [
|
|
60
51
|
{
|
|
@@ -65,7 +56,7 @@ let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
|
|
|
65
56
|
: [
|
|
66
57
|
{
|
|
67
58
|
provide: graphql_1.SCHEMA_OVERRIDE,
|
|
68
|
-
deps: [
|
|
59
|
+
deps: [neo4j_service_1.UtilService, injection_tokens_1.NEO4J_DRIVER],
|
|
69
60
|
useFactory: (util, driver) => (schema) => __awaiter(this, void 0, void 0, function* () { return util.augmentSchema(schema)(driver); })
|
|
70
61
|
}
|
|
71
62
|
])
|
|
@@ -75,9 +66,9 @@ let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
|
|
|
75
66
|
};
|
|
76
67
|
Neo4JModule = Neo4JModule_1 = __decorate([
|
|
77
68
|
(0, core_1.Module)({
|
|
78
|
-
providers: []
|
|
69
|
+
providers: [neo4j_service_1.UtilService]
|
|
79
70
|
})
|
|
80
71
|
], Neo4JModule);
|
|
81
72
|
exports.Neo4JModule = Neo4JModule;
|
|
82
73
|
__exportStar(require("./injection.tokens"), exports);
|
|
83
|
-
__exportStar(require("./
|
|
74
|
+
__exportStar(require("./neo4j.service"), exports);
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { InjectionToken } from '@rxdi/core';
|
|
2
|
-
import {
|
|
3
|
-
import { ResponseToolkit } from 'hapi';
|
|
2
|
+
import { GraphQLSchema } from 'graphql';
|
|
4
3
|
import { Driver } from 'neo4j-driver';
|
|
5
4
|
export declare const NEO4J_MODULE_CONFIG: InjectionToken<NEO4J_MODULE_CONFIG>;
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
query?: {
|
|
12
|
-
exclude: IExcludeType[];
|
|
13
|
-
};
|
|
5
|
+
export interface NEO4J_MODULE_CONFIG {
|
|
6
|
+
username?: string;
|
|
7
|
+
password?: string;
|
|
8
|
+
address?: string | 'bolt://localhost:7687';
|
|
9
|
+
schemaOverride?(schema: GraphQLSchema): GraphQLSchema;
|
|
14
10
|
}
|
|
15
11
|
export interface RelationshipType {
|
|
16
|
-
searchIndex
|
|
17
|
-
replaceWith
|
|
12
|
+
searchIndex?: string;
|
|
13
|
+
replaceWith?: string;
|
|
14
|
+
extends?: string;
|
|
18
15
|
}
|
|
19
16
|
export interface Relationship {
|
|
20
17
|
direction: 'IN' | 'OUT';
|
|
@@ -24,19 +21,10 @@ export interface Relationship {
|
|
|
24
21
|
export interface RelationshipMap {
|
|
25
22
|
[key: string]: RelationshipType;
|
|
26
23
|
}
|
|
27
|
-
export interface NEO4J_MODULE_CONFIG {
|
|
28
|
-
username?: string;
|
|
29
|
-
password?: string;
|
|
30
|
-
address?: string | 'bolt://localhost:7687';
|
|
31
|
-
debug?: boolean;
|
|
32
|
-
auth?: boolean;
|
|
33
|
-
context?: any;
|
|
34
|
-
onRequest?(next: any, request: Request, h: ResponseToolkit, err: Error): Promise<any>;
|
|
35
|
-
schemaOverride?(schema: GraphQLSchema): GraphQLSchema;
|
|
36
|
-
}
|
|
37
24
|
/**
|
|
38
25
|
* Neo4j driver @rxdi injection token
|
|
39
26
|
*/
|
|
40
27
|
export declare const NEO4J_DRIVER: InjectionToken<unknown>;
|
|
41
28
|
export declare type NEO4J_DRIVER = Driver;
|
|
42
29
|
export { Driver } from 'neo4j-driver';
|
|
30
|
+
export declare function gql(...args: any[]): any;
|
package/dist/injection.tokens.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NEO4J_DRIVER = exports.NEO4J_MODULE_CONFIG = void 0;
|
|
3
|
+
exports.gql = exports.NEO4J_DRIVER = exports.NEO4J_MODULE_CONFIG = void 0;
|
|
4
4
|
const core_1 = require("@rxdi/core");
|
|
5
5
|
exports.NEO4J_MODULE_CONFIG = new core_1.InjectionToken('GAPI_NEO4J_MODULE_CONFIG');
|
|
6
6
|
/**
|
|
7
7
|
* Neo4j driver @rxdi injection token
|
|
8
8
|
*/
|
|
9
|
-
exports.NEO4J_DRIVER = new core_1.InjectionToken('
|
|
9
|
+
exports.NEO4J_DRIVER = new core_1.InjectionToken('GAPI_NEO4J_MODULE_DRIVER');
|
|
10
|
+
function gql(...args) {
|
|
11
|
+
const literals = args[0];
|
|
12
|
+
let result = typeof literals === 'string' ? literals : literals[0];
|
|
13
|
+
for (let i = 1; i < args.length; i++) {
|
|
14
|
+
if (args[i] && args[i].kind && args[i].kind === 'Document') {
|
|
15
|
+
result += args[i].loc.source.body;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
result += args[i];
|
|
19
|
+
}
|
|
20
|
+
result += literals[i];
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
exports.gql = gql;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NEO4J_DRIVER, NEO4J_MODULE_CONFIG } from '
|
|
1
|
+
import { NEO4J_DRIVER, NEO4J_MODULE_CONFIG } from './injection.tokens';
|
|
2
2
|
import * as neo4j from 'neo4j-driver';
|
|
3
3
|
import { GraphQLSchema } from 'graphql';
|
|
4
4
|
export declare class UtilService {
|
|
@@ -6,9 +6,10 @@ export declare class UtilService {
|
|
|
6
6
|
constructor(config: NEO4J_MODULE_CONFIG);
|
|
7
7
|
private extendSchemaDirectives;
|
|
8
8
|
private validateSchema;
|
|
9
|
+
private replaceAll;
|
|
9
10
|
augmentSchema(schema: GraphQLSchema): (driver: NEO4J_DRIVER) => Promise<GraphQLSchema>;
|
|
10
11
|
mergeSchemas(...schemas: GraphQLSchema[]): GraphQLSchema;
|
|
11
|
-
|
|
12
|
+
createDriver(): neo4j.Driver;
|
|
12
13
|
generateTypeDefs(schema: GraphQLSchema): string;
|
|
13
|
-
private
|
|
14
|
+
private findSchemaExtensions;
|
|
14
15
|
}
|
|
@@ -23,7 +23,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.UtilService = void 0;
|
|
25
25
|
const core_1 = require("@rxdi/core");
|
|
26
|
-
const injection_tokens_1 = require("
|
|
26
|
+
const injection_tokens_1 = require("./injection.tokens");
|
|
27
27
|
const graphql_tools_1 = require("graphql-tools");
|
|
28
28
|
const neo4j = require("neo4j-driver");
|
|
29
29
|
const graphql_1 = require("@neo4j/graphql");
|
|
@@ -42,6 +42,9 @@ let UtilService = class UtilService {
|
|
|
42
42
|
throw new Error(JSON.stringify(schemaErrors));
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
replaceAll(value) {
|
|
46
|
+
return (search) => (replacement) => value.split(search).join(replacement);
|
|
47
|
+
}
|
|
45
48
|
augmentSchema(schema) {
|
|
46
49
|
return (driver) => __awaiter(this, void 0, void 0, function* () {
|
|
47
50
|
this.validateSchema(schema);
|
|
@@ -51,7 +54,8 @@ let UtilService = class UtilService {
|
|
|
51
54
|
driver,
|
|
52
55
|
assumeValidSDL: true,
|
|
53
56
|
});
|
|
54
|
-
|
|
57
|
+
const augmentedSchema = yield neoSchema.getSchema();
|
|
58
|
+
return this.extendSchemaDirectives(augmentedSchema, schema);
|
|
55
59
|
});
|
|
56
60
|
}
|
|
57
61
|
mergeSchemas(...schemas) {
|
|
@@ -59,40 +63,48 @@ let UtilService = class UtilService {
|
|
|
59
63
|
schemas: schemas.filter(s => !!s)
|
|
60
64
|
}), schemas.filter(s => !!s)[0]);
|
|
61
65
|
}
|
|
62
|
-
|
|
66
|
+
createDriver() {
|
|
63
67
|
return neo4j.driver(this.config.address || 'bolt://localhost:7687', neo4j.auth.basic(this.config.username, this.config.password));
|
|
64
68
|
}
|
|
65
69
|
generateTypeDefs(schema) {
|
|
66
|
-
return Object.values(this.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const relations = {};
|
|
70
|
-
Object.values(schema.getQueryType()).forEach(field => {
|
|
71
|
-
if (!field) {
|
|
72
|
-
return;
|
|
70
|
+
return Object.values(this.findSchemaExtensions(schema)).reduce((curr, prev) => {
|
|
71
|
+
if (prev.extends) {
|
|
72
|
+
return `${curr}\n${prev.extends}`;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
74
|
+
return this.replaceAll(curr)(prev.searchIndex)(prev.replaceWith);
|
|
75
|
+
}, (0, graphql_2.printSchema)(schema));
|
|
76
|
+
}
|
|
77
|
+
findSchemaExtensions(schema) {
|
|
78
|
+
const extensions = {};
|
|
79
|
+
for (const field of Object.values(schema.getQueryType()).filter(i => !!i)) {
|
|
80
|
+
if (typeof field !== 'string') {
|
|
81
|
+
Object.keys(field).reduce((prev, currentType) => {
|
|
82
|
+
const type = field[currentType].type;
|
|
83
|
+
if (type['extend']) {
|
|
84
|
+
extensions[currentType] = {
|
|
85
|
+
extends: `extend type ${type.name} ${type['extend']}`
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (type && typeof type.getFields === 'function') {
|
|
89
|
+
for (const [key, value] of Object.entries(type.getFields())) {
|
|
90
|
+
extensions[key] =
|
|
91
|
+
extensions[key] || {};
|
|
92
|
+
const relation = value['relation'];
|
|
93
|
+
const directive = typeof relation === 'object' ?
|
|
94
|
+
`@relationship(type: "${relation.name}", direction: ${relation.direction})`
|
|
95
|
+
:
|
|
96
|
+
value['directive'];
|
|
97
|
+
if (directive) {
|
|
98
|
+
extensions[key].searchIndex = `${key}: ${value.type}`;
|
|
99
|
+
extensions[key].replaceWith = `${extensions[key].searchIndex} ${directive}`;
|
|
100
|
+
}
|
|
89
101
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return
|
|
102
|
+
}
|
|
103
|
+
return prev;
|
|
104
|
+
}, {});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return extensions;
|
|
96
108
|
}
|
|
97
109
|
};
|
|
98
110
|
UtilService = __decorate([
|
package/package.json
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"lint": "tslint -c tslint.json 'src/**/*.{ts,tsx}'",
|
|
14
|
-
"pretest": "npm run lint",
|
|
15
|
-
"test": "echo Test Neo4J",
|
|
16
|
-
"build": "tsc || true"
|
|
17
|
-
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "https://github.com/rxdi/neo4j"
|
|
21
|
-
},
|
|
22
|
-
"author": "Kristiyan Tachev (@Stradivario)",
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"bugs": {
|
|
25
|
-
"url": "https://github.com/rxdi/neo4j/issues"
|
|
26
|
-
},
|
|
27
|
-
"homepage": "https://github.com/rxdi/neo4j/blob/master/README.md",
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"@neo4j/graphql": "^3.8.0",
|
|
30
|
-
"neo4j-driver": "^5.0.1"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"graphql": "^14.5.8",
|
|
34
|
-
"@types/graphql": "^14.5.0",
|
|
35
|
-
"graphql-tools": "^5.0.0",
|
|
36
|
-
"@rxdi/core": "^0.7.152",
|
|
37
|
-
"@rxdi/graphql": "^0.7.152",
|
|
38
|
-
"@types/hapi": "^18.0.4",
|
|
39
|
-
"@types/jest": "^24.0.22",
|
|
40
|
-
"@types/node": "^12.0.10",
|
|
41
|
-
"jest": "^24.8.0",
|
|
42
|
-
"jest-cli": "^24.8.1",
|
|
43
|
-
"ts-jest": "^24.0.2",
|
|
44
|
-
"tslint": "^5.20.1",
|
|
45
|
-
"tslint-language-service": "^0.9.9",
|
|
46
|
-
"typescript": "^4.3.5"
|
|
47
|
-
},
|
|
48
|
-
"jest": {
|
|
49
|
-
"testEnvironment": "node",
|
|
50
|
-
"testPathIgnorePatterns": [
|
|
51
|
-
"/node_modules/"
|
|
2
|
+
"name": "@rxdi/neo4j",
|
|
3
|
+
"version": "0.7.154",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"typings": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
52
11
|
],
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
|
|
12
|
+
"scripts": {
|
|
13
|
+
"lint": "tslint -c tslint.json 'src/**/*.{ts,tsx}'",
|
|
14
|
+
"pretest": "npm run lint",
|
|
15
|
+
"test": "echo Test Neo4J",
|
|
16
|
+
"build": "tsc || true"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/rxdi/neo4j"
|
|
21
|
+
},
|
|
22
|
+
"author": "Kristiyan Tachev (@Stradivario)",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/rxdi/neo4j/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/rxdi/neo4j/blob/master/README.md",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@neo4j/graphql": "^3.8.0",
|
|
30
|
+
"neo4j-driver": "^5.0.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"graphql": "^14.5.8",
|
|
34
|
+
"@types/graphql": "^14.5.0",
|
|
35
|
+
"graphql-tools": "^5.0.0",
|
|
36
|
+
"@rxdi/core": "^0.7.153",
|
|
37
|
+
"@rxdi/graphql": "^0.7.153",
|
|
38
|
+
"@types/hapi": "^18.0.4",
|
|
39
|
+
"@types/jest": "^24.0.22",
|
|
40
|
+
"@types/node": "^12.0.10",
|
|
41
|
+
"jest": "^24.8.0",
|
|
42
|
+
"jest-cli": "^24.8.1",
|
|
43
|
+
"ts-jest": "^24.0.2",
|
|
44
|
+
"tslint": "^5.20.1",
|
|
45
|
+
"tslint-language-service": "^0.9.9",
|
|
46
|
+
"typescript": "^4.3.5"
|
|
67
47
|
},
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
48
|
+
"jest": {
|
|
49
|
+
"testEnvironment": "node",
|
|
50
|
+
"testPathIgnorePatterns": [
|
|
51
|
+
"/node_modules/"
|
|
52
|
+
],
|
|
53
|
+
"coverageReporters": [
|
|
54
|
+
"lcov",
|
|
55
|
+
"html"
|
|
56
|
+
],
|
|
57
|
+
"rootDir": "./",
|
|
58
|
+
"moduleFileExtensions": [
|
|
59
|
+
"ts",
|
|
60
|
+
"tsx",
|
|
61
|
+
"js",
|
|
62
|
+
"json",
|
|
63
|
+
"node"
|
|
64
|
+
],
|
|
65
|
+
"transform": {
|
|
66
|
+
"\\.(ts|tsx)$": "ts-jest"
|
|
67
|
+
},
|
|
68
|
+
"testRegex": "/src/.*\\.spec.(ts|tsx|js)$",
|
|
69
|
+
"verbose": true,
|
|
70
|
+
"collectCoverage": true
|
|
71
|
+
}
|
|
72
72
|
}
|
package/dist/services/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './util.service';
|
package/dist/services/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./util.service"), exports);
|