@rxdi/neo4j 0.7.153 → 0.7.155
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 +11 -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} +8 -4
- package/dist/{services/util.service.js → neo4j.service.js} +62 -33
- package/dist/ogm.provider.d.ts +4 -0
- package/dist/ogm.provider.js +16 -0
- package/package.json +5 -4
- 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,23 @@ 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
|
+
const ogm_provider_1 = require("./ogm.provider");
|
|
34
35
|
let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
|
|
35
36
|
static forRoot(config = {}) {
|
|
36
37
|
return {
|
|
37
38
|
module: Neo4JModule_1,
|
|
38
39
|
providers: [
|
|
40
|
+
neo4j_service_1.UtilService,
|
|
39
41
|
{
|
|
40
42
|
provide: injection_tokens_1.NEO4J_MODULE_CONFIG,
|
|
41
43
|
useValue: config
|
|
42
44
|
},
|
|
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
|
-
]),
|
|
45
|
+
{
|
|
46
|
+
provide: injection_tokens_1.NEO4J_DRIVER,
|
|
47
|
+
deps: [neo4j_service_1.UtilService],
|
|
48
|
+
useFactory: (util) => util.createDriver()
|
|
49
|
+
},
|
|
58
50
|
...(config.schemaOverride
|
|
59
51
|
? [
|
|
60
52
|
{
|
|
@@ -65,7 +57,7 @@ let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
|
|
|
65
57
|
: [
|
|
66
58
|
{
|
|
67
59
|
provide: graphql_1.SCHEMA_OVERRIDE,
|
|
68
|
-
deps: [
|
|
60
|
+
deps: [neo4j_service_1.UtilService, injection_tokens_1.NEO4J_DRIVER],
|
|
69
61
|
useFactory: (util, driver) => (schema) => __awaiter(this, void 0, void 0, function* () { return util.augmentSchema(schema)(driver); })
|
|
70
62
|
}
|
|
71
63
|
])
|
|
@@ -75,9 +67,9 @@ let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
|
|
|
75
67
|
};
|
|
76
68
|
Neo4JModule = Neo4JModule_1 = __decorate([
|
|
77
69
|
(0, core_1.Module)({
|
|
78
|
-
providers: []
|
|
70
|
+
providers: [neo4j_service_1.UtilService, ogm_provider_1.OGMProvider]
|
|
79
71
|
})
|
|
80
72
|
], Neo4JModule);
|
|
81
73
|
exports.Neo4JModule = Neo4JModule;
|
|
82
74
|
__exportStar(require("./injection.tokens"), exports);
|
|
83
|
-
__exportStar(require("./
|
|
75
|
+
__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,14 +1,18 @@
|
|
|
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
|
+
import { OGMProvider } from './ogm.provider';
|
|
4
5
|
export declare class UtilService {
|
|
5
6
|
private config;
|
|
6
|
-
|
|
7
|
+
private ogmProvider;
|
|
8
|
+
constructor(config: NEO4J_MODULE_CONFIG, ogmProvider: OGMProvider);
|
|
7
9
|
private extendSchemaDirectives;
|
|
8
10
|
private validateSchema;
|
|
11
|
+
private replaceAll;
|
|
9
12
|
augmentSchema(schema: GraphQLSchema): (driver: NEO4J_DRIVER) => Promise<GraphQLSchema>;
|
|
13
|
+
initOgmClient(typeDefs: string): (driver: NEO4J_DRIVER) => Promise<void>;
|
|
10
14
|
mergeSchemas(...schemas: GraphQLSchema[]): GraphQLSchema;
|
|
11
|
-
|
|
15
|
+
createDriver(): neo4j.Driver;
|
|
12
16
|
generateTypeDefs(schema: GraphQLSchema): string;
|
|
13
|
-
private
|
|
17
|
+
private findSchemaExtensions;
|
|
14
18
|
}
|
|
@@ -23,14 +23,17 @@ 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");
|
|
30
30
|
const graphql_2 = require("graphql");
|
|
31
|
+
const ogm_provider_1 = require("./ogm.provider");
|
|
32
|
+
const graphql_ogm_1 = require("@neo4j/graphql-ogm");
|
|
31
33
|
let UtilService = class UtilService {
|
|
32
|
-
constructor(config) {
|
|
34
|
+
constructor(config, ogmProvider) {
|
|
33
35
|
this.config = config;
|
|
36
|
+
this.ogmProvider = ogmProvider;
|
|
34
37
|
}
|
|
35
38
|
extendSchemaDirectives(augmentedSchema, schema) {
|
|
36
39
|
augmentedSchema['_directives'] = schema['_directives'];
|
|
@@ -42,16 +45,34 @@ let UtilService = class UtilService {
|
|
|
42
45
|
throw new Error(JSON.stringify(schemaErrors));
|
|
43
46
|
}
|
|
44
47
|
}
|
|
48
|
+
replaceAll(value) {
|
|
49
|
+
return (search) => (replacement) => value.split(search).join(replacement);
|
|
50
|
+
}
|
|
45
51
|
augmentSchema(schema) {
|
|
46
52
|
return (driver) => __awaiter(this, void 0, void 0, function* () {
|
|
47
53
|
this.validateSchema(schema);
|
|
48
54
|
const typeDefs = this.generateTypeDefs(schema);
|
|
55
|
+
yield this.initOgmClient(typeDefs)(driver);
|
|
49
56
|
const neoSchema = new graphql_1.Neo4jGraphQL({
|
|
50
57
|
typeDefs,
|
|
51
58
|
driver,
|
|
52
59
|
assumeValidSDL: true,
|
|
53
60
|
});
|
|
54
|
-
|
|
61
|
+
const augmentedSchema = yield neoSchema.getSchema();
|
|
62
|
+
const newSchema = this.extendSchemaDirectives(augmentedSchema, schema);
|
|
63
|
+
return newSchema;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
initOgmClient(typeDefs) {
|
|
67
|
+
return (driver) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const ogm = new graphql_ogm_1.OGM({
|
|
69
|
+
assumeValidSDL: true,
|
|
70
|
+
assumeValid: true,
|
|
71
|
+
typeDefs,
|
|
72
|
+
driver
|
|
73
|
+
});
|
|
74
|
+
yield ogm.init();
|
|
75
|
+
this.ogmProvider.client = ogm;
|
|
55
76
|
});
|
|
56
77
|
}
|
|
57
78
|
mergeSchemas(...schemas) {
|
|
@@ -59,45 +80,53 @@ let UtilService = class UtilService {
|
|
|
59
80
|
schemas: schemas.filter(s => !!s)
|
|
60
81
|
}), schemas.filter(s => !!s)[0]);
|
|
61
82
|
}
|
|
62
|
-
|
|
83
|
+
createDriver() {
|
|
63
84
|
return neo4j.driver(this.config.address || 'bolt://localhost:7687', neo4j.auth.basic(this.config.username, this.config.password));
|
|
64
85
|
}
|
|
65
86
|
generateTypeDefs(schema) {
|
|
66
|
-
return Object.values(this.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const relations = {};
|
|
70
|
-
Object.values(schema.getQueryType()).forEach(field => {
|
|
71
|
-
if (!field) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (typeof field === 'string') {
|
|
75
|
-
return;
|
|
87
|
+
return Object.values(this.findSchemaExtensions(schema)).reduce((curr, prev) => {
|
|
88
|
+
if (prev.extends) {
|
|
89
|
+
return `${curr}\n${prev.extends}`;
|
|
76
90
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
return this.replaceAll(curr)(prev.searchIndex)(prev.replaceWith);
|
|
92
|
+
}, (0, graphql_2.printSchema)(schema));
|
|
93
|
+
}
|
|
94
|
+
findSchemaExtensions(schema) {
|
|
95
|
+
const extensions = {};
|
|
96
|
+
for (const field of Object.values(schema.getQueryType()).filter(i => !!i)) {
|
|
97
|
+
if (typeof field !== 'string') {
|
|
98
|
+
Object.keys(field).reduce((prev, currentType) => {
|
|
99
|
+
const type = field[currentType].type;
|
|
100
|
+
if (type['extend']) {
|
|
101
|
+
extensions[currentType] = {
|
|
102
|
+
extends: `extend type ${type.name} ${type['extend']}`
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (type && typeof type.getFields === 'function') {
|
|
106
|
+
for (const [key, value] of Object.entries(type.getFields())) {
|
|
107
|
+
extensions[key] =
|
|
108
|
+
extensions[key] || {};
|
|
109
|
+
const relation = value['relation'];
|
|
110
|
+
const directive = typeof relation === 'object' ?
|
|
111
|
+
`@relationship(type: "${relation.name}", direction: ${relation.direction})`
|
|
112
|
+
:
|
|
113
|
+
value['directive'];
|
|
114
|
+
if (directive) {
|
|
115
|
+
extensions[key].searchIndex = `${key}: ${value.type}`;
|
|
116
|
+
extensions[key].replaceWith = `${extensions[key].searchIndex} ${directive}`;
|
|
117
|
+
}
|
|
89
118
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return
|
|
119
|
+
}
|
|
120
|
+
return prev;
|
|
121
|
+
}, {});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return extensions;
|
|
96
125
|
}
|
|
97
126
|
};
|
|
98
127
|
UtilService = __decorate([
|
|
99
128
|
(0, core_1.Injectable)(),
|
|
100
129
|
__param(0, (0, core_1.Inject)(injection_tokens_1.NEO4J_MODULE_CONFIG)),
|
|
101
|
-
__metadata("design:paramtypes", [Object])
|
|
130
|
+
__metadata("design:paramtypes", [Object, ogm_provider_1.OGMProvider])
|
|
102
131
|
], UtilService);
|
|
103
132
|
exports.UtilService = UtilService;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.OGMProvider = void 0;
|
|
10
|
+
const core_1 = require("@gapi/core");
|
|
11
|
+
let OGMProvider = class OGMProvider {
|
|
12
|
+
};
|
|
13
|
+
OGMProvider = __decorate([
|
|
14
|
+
(0, core_1.Injectable)()
|
|
15
|
+
], OGMProvider);
|
|
16
|
+
exports.OGMProvider = OGMProvider;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdi/neo4j",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.155",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -26,15 +26,16 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/rxdi/neo4j/blob/master/README.md",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@neo4j/graphql": "^3.
|
|
29
|
+
"@neo4j/graphql": "^3.9.0",
|
|
30
|
+
"@neo4j/graphql-ogm": "^3.9.0",
|
|
30
31
|
"neo4j-driver": "^5.0.1"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"graphql": "^14.5.8",
|
|
34
35
|
"@types/graphql": "^14.5.0",
|
|
35
36
|
"graphql-tools": "^5.0.0",
|
|
36
|
-
"@rxdi/core": "^0.7.
|
|
37
|
-
"@rxdi/graphql": "^0.7.
|
|
37
|
+
"@rxdi/core": "^0.7.153",
|
|
38
|
+
"@rxdi/graphql": "^0.7.153",
|
|
38
39
|
"@types/hapi": "^18.0.4",
|
|
39
40
|
"@types/jest": "^24.0.22",
|
|
40
41
|
"@types/node": "^12.0.10",
|
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);
|