@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 CHANGED
@@ -4,4 +4,4 @@ export declare class Neo4JModule {
4
4
  static forRoot(config?: NEO4J_MODULE_CONFIG): ModuleWithServices;
5
5
  }
6
6
  export * from './injection.tokens';
7
- export * from './services';
7
+ export * from './neo4j.service';
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 util_service_1 = require("./services/util.service");
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
- ...(config.onRequest
44
- ? [
45
- {
46
- provide: graphql_1.ON_REQUEST_HANDLER,
47
- deps: [injection_tokens_1.NEO4J_MODULE_CONFIG],
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: [util_service_1.UtilService, injection_tokens_1.NEO4J_DRIVER],
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("./services"), exports);
74
+ __exportStar(require("./neo4j.service"), exports);
@@ -1,20 +1,17 @@
1
1
  import { InjectionToken } from '@rxdi/core';
2
- import { GraphQLObjectType, GraphQLSchema } from 'graphql';
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 declare type IExcludeType = string | Function | GraphQLObjectType;
7
- export interface ExcludedTypes {
8
- mutation?: {
9
- exclude: IExcludeType[];
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: string;
17
- replaceWith: string;
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;
@@ -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('GAPI_NEO4J_MODULE_CONFIG');
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 '../injection.tokens';
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
- assignDriverToContext(): neo4j.Driver;
12
+ createDriver(): neo4j.Driver;
12
13
  generateTypeDefs(schema: GraphQLSchema): string;
13
- private findRelations;
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("../injection.tokens");
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
- return this.extendSchemaDirectives(yield neoSchema.getSchema(), schema);
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
- assignDriverToContext() {
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.findRelations(schema)).reduce((curr, prev) => curr.replace(prev.searchIndex, prev.replaceWith), (0, graphql_2.printSchema)(schema));
67
- }
68
- findRelations(schema) {
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
- if (typeof field === 'string') {
75
- return;
76
- }
77
- Object.keys(field).reduce((prev, currentType) => {
78
- const type = field[currentType].type;
79
- if (type && typeof type.getFields === 'function') {
80
- Object.entries(type.getFields()).map(([key, value]) => {
81
- relations[currentType] =
82
- relations[currentType] || {};
83
- const relation = value['relation'];
84
- if (typeof relation === 'object') {
85
- relations[currentType].searchIndex = `${key}: ${value.type}`;
86
- const cyper = relation.cyper ||
87
- `@relationship(type: "${relation.name}", direction: ${relation.direction})`;
88
- relations[currentType].replaceWith = `${relations[currentType].searchIndex} ${cyper}`;
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
- return prev;
93
- }, {});
94
- });
95
- return relations;
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
- "name": "@rxdi/neo4j",
3
- "version": "0.7.153",
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"
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
- "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"
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
- "testRegex": "/src/.*\\.spec.(ts|tsx|js)$",
69
- "verbose": true,
70
- "collectCoverage": true
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
  }
@@ -1 +0,0 @@
1
- export * from './util.service';
@@ -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);