@rxdi/neo4j 0.7.152 → 0.7.153

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/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/rxdi/neo4j.svg?branch=master)](https://travis-ci.org/rxdi/neo4j)
4
4
 
5
5
  ##### For questions/issues you can write ticket [here](http://gitlab.youvolio.com/rxdi/neo4j/issues)
6
+
6
7
  ##### This module is intended to be used with [rxdi](https://github.com/rxdi/core)
7
8
 
8
9
  > With this module by just defining your types and adding them inside `types` property you will have `CRUD` operations generated automatically
@@ -12,6 +13,7 @@
12
13
  > Why is this so cool ? :)) Because while you are writing your schema you can have also `queries` and `mutations` prepared for you to execute inside `Neo4J Graph`
13
14
 
14
15
  ## Installation and basic examples:
16
+
15
17
  ##### To install this module, run:
16
18
 
17
19
  ```bash
@@ -21,86 +23,56 @@ $ npm install @rxdi/neo4j --save
21
23
  ## Consuming @rxdi/neo4j
22
24
 
23
25
  ##### Simple approach
26
+
24
27
  ```typescript
25
28
  import { Module, CoreModule } from '@gapi/core';
26
29
  import { Neo4JModule } from '@rxdi/neo4j';
27
30
  import { UserType } from './user.type';
28
31
 
29
32
  @Module({
30
- imports: [
31
- CoreModule.forRoot(),
32
- Neo4JModule.forRoot({
33
- types: [UserType],
34
- password: '12345678',
35
- username: 'neo4j',
36
- address: 'bolt://localhost:7687',
37
- excludedTypes: {
38
- mutation: {
39
- exclude: [UserType]
40
- }
41
- }
42
- })
43
- ]
33
+ imports: [
34
+ CoreModule.forRoot(),
35
+ Neo4JModule.forRoot({
36
+ password: '12345678',
37
+ username: 'neo4j',
38
+ address: 'bolt://localhost:7687',
39
+ }),
40
+ ],
44
41
  })
45
42
  export class AppModule {}
46
43
  ```
47
44
 
48
- ##### Simple GraphqlObject `UserType`
49
- ```typescript
50
- import { GraphQLObjectType, GraphQLString } from 'graphql';
51
-
52
- export const UserType = new GraphQLObjectType({
53
- name: 'User',
54
- fields: () => ({
55
- userName: {
56
- type: GraphQLString
57
- },
58
- })
59
- });
60
-
61
- ```
62
-
63
-
64
45
  ##### More complex Approach
65
46
 
66
47
  ```typescript
67
48
  import { Module, CoreModule } from '@gapi/core';
68
- import { Neo4JModule } from '@rxdi/neo4j';
69
- import { UserType } from './user.type';
49
+ import { Neo4JModule, UtilService } from '@rxdi/neo4j';
70
50
  import { GraphQLSchema } from 'graphql';
71
51
 
72
52
  @Module({
73
- imports: [
74
- Neo4JModule.forRoot({
75
- types: [
76
- UserType
77
- ],
78
- schemaOverride(schema: GraphQLSchema) {
79
- return neo4jgql.makeAugmentedSchema({
80
- typeDefs: printSchema(schema),
81
- config: {
82
- mutation: {
83
- exclude: [UserType.name]
84
- }
85
- }
86
- });
87
- },
88
- async onRequest(graphqlRequest, request, h, err) {
89
- const context = {
90
- driver: neo4j.driver(
91
- 'bolt://localhost:7687',
92
- neo4j.auth.basic('neo4j', '12345678')
93
- )
94
- }
95
- return graphqlRequest(context);
96
- }
97
- }),
98
- ]
53
+ imports: [
54
+ Neo4JModule.forRoot({
55
+ schemaOverride(schema: GraphQLSchema) {
56
+ const neo4JUtils = Container.get(UtilService);
57
+ neo4JUtils.validateSchema(schema);
58
+
59
+ const typeDefs = neo4JUtils.generateTypeDefs(schema);
60
+
61
+ const neoSchema = new Neo4jGraphQL({
62
+ typeDefs,
63
+ driver,
64
+ assumeValidSDL: true,
65
+ });
66
+ return neoSchema;
67
+ },
68
+ }),
69
+ ],
99
70
  })
100
71
  export class AppModule {}
101
72
  ```
102
73
 
103
74
  ##### Import inside AppModule or CoreModule
75
+
104
76
  ```typescript
105
77
  import { Module, CoreModule } from '@gapi/core';
106
78
  import { VoyagerModule } from '@gapi/voyager';
@@ -112,38 +84,26 @@ import { Channel } from './types/channel/channel.type';
112
84
  import { AttachmentType } from './types/attachment/attachment.type';
113
85
  import { ToUpperCaseDirective } from './core/directives/toUppercase.directive';
114
86
 
115
- // import { AppQueriesController } from './app.controller';
116
- // Uncomment to override some methods which are provided from neo4js
117
-
118
87
  @Module({
119
- // controllers: [AppQueriesController],
120
- imports: [
121
- CoreModule.forRoot({
122
- graphql: { directives: [ToUpperCaseDirective] }
123
- }),
124
- Neo4JModule.forRoot({
125
- types: [UserContext, User, Message, Channel, AttachmentType],
126
- username: 'neo4j',
127
- password: '12345678',
128
- address: 'bolt://localhost:7687',
129
- context: {},
130
- excludedTypes: {
131
- mutation: {
132
- exclude: [UserContext]
133
- }
134
- }
135
- }),
136
- // Optional voyager but you will not regret to have mind mapping for all your graph api :) npm i @gapi/voyager
137
- VoyagerModule.forRoot({
138
- endpointUrl: '/graphql',
139
- path: '/voyager'
140
- })
141
- ]
88
+ imports: [
89
+ CoreModule.forRoot({
90
+ graphql: { directives: [ToUpperCaseDirective] },
91
+ }),
92
+ Neo4JModule.forRoot({
93
+ username: 'neo4j',
94
+ password: '12345678',
95
+ address: 'bolt://localhost:7687',
96
+ }),
97
+ // Optional voyager but you will not regret to have mind mapping for all your graph api :) npm i @gapi/voyager
98
+ VoyagerModule.forRoot({
99
+ endpointUrl: '/graphql',
100
+ path: '/voyager',
101
+ }),
102
+ ],
142
103
  })
143
104
  export class AppModule {}
144
105
  ```
145
106
 
146
-
147
107
  ##### Graphql Directive
148
108
 
149
109
  ```typescript
@@ -151,141 +111,13 @@ import { GraphQLCustomDirective } from '@gapi/core';
151
111
  import { DirectiveLocation } from 'graphql';
152
112
 
153
113
  export const ToUpperCaseDirective = new GraphQLCustomDirective<string>({
154
- name: 'toUpperCase',
155
- description: 'change the case of a string to uppercase',
156
- locations: [DirectiveLocation.FIELD],
157
- resolve: async resolve => (await resolve()).toUpperCase()
114
+ name: 'toUpperCase',
115
+ description: 'change the case of a string to uppercase',
116
+ locations: [DirectiveLocation.FIELD],
117
+ resolve: async (resolve) => (await resolve()).toUpperCase(),
158
118
  });
159
119
  ```
160
120
 
161
-
162
- ##### Interceptor
163
- ```typescript
164
- import { Observable } from 'rxjs';
165
- import { tap } from 'rxjs/operators';
166
- import { Service } from '@rxdi/core';
167
- import { InterceptResolver, GenericGapiResolversType } from '@gapi/core';
168
- import { GraphQLContext } from '../../app.context';
169
-
170
- @Service()
171
- export class LoggerInterceptor implements InterceptResolver {
172
- intercept(
173
- chainable$: Observable<any>,
174
- context: GraphQLContext,
175
- payload,
176
- descriptor: GenericGapiResolversType
177
- ) {
178
- console.log('Before...');
179
- const now = Date.now();
180
- return chainable$.pipe(
181
- tap(() => console.log(`After... ${Date.now() - now}ms`))
182
- );
183
- }
184
- }
185
- ```
186
-
187
-
188
- ##### Guard
189
- ```typescript
190
- import { Service } from '@rxdi/core';
191
- import { CanActivateResolver, GenericGapiResolversType } from '@gapi/core';
192
- import { GraphQLContext } from '../../app.context';
193
-
194
- @Service()
195
- export class AdminOnly implements CanActivateResolver {
196
- canActivate(
197
- context: GraphQLContext,
198
- payload,
199
- descriptor: GenericGapiResolversType
200
- ) {
201
- return false;
202
- }
203
- }
204
- ```
205
-
206
-
207
- ##### Controller
208
- > The name of our class methods is important since we want to override default `neo4j-graphql` autogenerated types
209
- ```typescript
210
-
211
- import { Controller, Type, Mutation, GraphQLString, Query, Interceptor, Guard } from '@gapi/core';
212
- import { Message } from './types/message/message.type';
213
- import { GraphQLContext } from './app.context';
214
- import { GraphQLList } from 'graphql';
215
- import { graphRequest } from '@rxdi/neo4j';
216
- import { IMessage } from './core/api-introspection';
217
- import { LoggerInterceptor } from './core/interceptors/logger.interceptor';
218
- import { AdminOnly } from './core/guards/admin-only.guard';
219
-
220
- @Controller()
221
- export class AppQueriesController {
222
-
223
- @Interceptor(LoggerInterceptor)
224
- @Type(Message)
225
- @Guard(AdminOnly)
226
- @Mutation({
227
- messageId: {
228
- type: GraphQLString
229
- },
230
- channelId: {
231
- type: GraphQLString
232
- }
233
- })
234
- CreateMessage(root, params, ctx: GraphQLContext, resolveInfo): Promise<IMessage> {
235
- return graphRequest<IMessage>(root, params, ctx, resolveInfo);
236
- }
237
-
238
- @Type(new GraphQLList(Message))
239
- @Query({
240
- messageId: {
241
- type: GraphQLString
242
- },
243
- channelId: {
244
- type: GraphQLString
245
- }
246
- })
247
- Messages(root, params, ctx: GraphQLContext, resolveInfo): Promise<IMessage[]> {
248
- return graphRequest<IMessage[]>(root, params, ctx, resolveInfo);
249
- }
250
-
251
- @Type(Message)
252
- @Query({
253
- messageId: {
254
- type: GraphQLString
255
- },
256
- channelId: {
257
- type: GraphQLString
258
- }
259
- })
260
- Message(root, params, ctx: GraphQLContext, resolveInfo): Promise<IMessage> {
261
- return graphRequest<IMessage>(root, params, ctx, resolveInfo);
262
- }
263
- }
264
-
265
- ```
266
-
267
- ##### Context interface
268
-
269
- ```typescript
270
- import { Driver } from '@rxdi/neo4j';
271
-
272
- export interface GraphQLContext {
273
- driver: Driver;
274
- }
275
- ```
276
-
277
- ##### Example query
278
- > Note: `offset`, `first`, `orderBy` are autogenerated for convenience
279
-
280
- ```graphql
281
- query {
282
- User(userName: "your-name", first: 10, offset: 10, orderBy: userName_asc) {
283
- userName
284
- }
285
- }
286
- ```
287
-
288
-
289
121
  TODO: Better documentation...
290
122
 
291
123
  Enjoy ! :)
package/dist/index.d.ts CHANGED
@@ -2,7 +2,6 @@ import { ModuleWithServices } from '@rxdi/core';
2
2
  import { NEO4J_MODULE_CONFIG } from './injection.tokens';
3
3
  export declare class Neo4JModule {
4
4
  static forRoot(config?: NEO4J_MODULE_CONFIG): ModuleWithServices;
5
- static forChild(types: string[] | Function[]): void;
6
5
  }
7
6
  export * from './injection.tokens';
8
- export * from './services/index';
7
+ export * from './services';
package/dist/index.js CHANGED
@@ -15,16 +15,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
15
15
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
25
+ });
26
+ };
18
27
  var Neo4JModule_1;
19
28
  Object.defineProperty(exports, "__esModule", { value: true });
20
29
  exports.Neo4JModule = void 0;
21
30
  const core_1 = require("@rxdi/core");
22
- const type_service_1 = require("./services/type.service");
23
31
  const injection_tokens_1 = require("./injection.tokens");
24
32
  const graphql_1 = require("@rxdi/graphql");
25
33
  const util_service_1 = require("./services/util.service");
26
- const rxjs_1 = require("rxjs");
27
- const operators_1 = require("rxjs/operators");
28
34
  let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
29
35
  static forRoot(config = {}) {
30
36
  return {
@@ -34,17 +40,6 @@ let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
34
40
  provide: injection_tokens_1.NEO4J_MODULE_CONFIG,
35
41
  useValue: config
36
42
  },
37
- {
38
- provide: injection_tokens_1.NEO4J_MODULE_CONFIG,
39
- deps: [injection_tokens_1.NEO4J_MODULE_CONFIG, type_service_1.TypeService],
40
- lazy: true,
41
- useFactory: (config, typeService) => (0, rxjs_1.of)(config).pipe((0, operators_1.map)(c => typeService.extendExcludedTypes(c)))
42
- },
43
- {
44
- provide: injection_tokens_1.Neo4JTypes,
45
- deps: [type_service_1.TypeService, injection_tokens_1.NEO4J_MODULE_CONFIG],
46
- useFactory: (typeService, config) => typeService.addTypes(config.types)
47
- },
48
43
  ...(config.onRequest
49
44
  ? [
50
45
  {
@@ -70,20 +65,19 @@ let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
70
65
  : [
71
66
  {
72
67
  provide: graphql_1.SCHEMA_OVERRIDE,
73
- deps: [util_service_1.UtilService],
74
- useFactory: (util) => (schema) => util.augmentSchema(schema)
68
+ deps: [util_service_1.UtilService, injection_tokens_1.NEO4J_DRIVER],
69
+ useFactory: (util, driver) => (schema) => __awaiter(this, void 0, void 0, function* () { return util.augmentSchema(schema)(driver); })
75
70
  }
76
71
  ])
77
72
  ]
78
73
  };
79
74
  }
80
- static forChild(types) { }
81
75
  };
82
76
  Neo4JModule = Neo4JModule_1 = __decorate([
83
77
  (0, core_1.Module)({
84
- providers: [type_service_1.TypeService]
78
+ providers: []
85
79
  })
86
80
  ], Neo4JModule);
87
81
  exports.Neo4JModule = Neo4JModule;
88
82
  __exportStar(require("./injection.tokens"), exports);
89
- __exportStar(require("./services/index"), exports);
83
+ __exportStar(require("./services"), exports);
@@ -1,13 +1,7 @@
1
1
  import { InjectionToken } from '@rxdi/core';
2
2
  import { GraphQLObjectType, GraphQLSchema } from 'graphql';
3
3
  import { ResponseToolkit } from 'hapi';
4
- import { AugmentSchemaConfig } from 'neo4j-graphql-js';
5
- export declare const Neo4JTypes: InjectionToken<GraphQLObjectType<any, any, {
6
- [key: string]: any;
7
- }>[]>;
8
- interface Neo4JTypesPrivate extends GraphQLObjectType {
9
- }
10
- export declare type Neo4JTypes = Neo4JTypesPrivate[];
4
+ import { Driver } from 'neo4j-driver';
11
5
  export declare const NEO4J_MODULE_CONFIG: InjectionToken<NEO4J_MODULE_CONFIG>;
12
6
  export declare type IExcludeType = string | Function | GraphQLObjectType;
13
7
  export interface ExcludedTypes {
@@ -31,18 +25,18 @@ export interface RelationshipMap {
31
25
  [key: string]: RelationshipType;
32
26
  }
33
27
  export interface NEO4J_MODULE_CONFIG {
34
- types?: GraphQLObjectType[];
35
28
  username?: string;
36
29
  password?: string;
37
30
  address?: string | 'bolt://localhost:7687';
38
- excludedTypes?: AugmentSchemaConfig;
39
31
  debug?: boolean;
40
32
  auth?: boolean;
41
33
  context?: any;
42
34
  onRequest?(next: any, request: Request, h: ResponseToolkit, err: Error): Promise<any>;
43
35
  schemaOverride?(schema: GraphQLSchema): GraphQLSchema;
44
36
  }
37
+ /**
38
+ * Neo4j driver @rxdi injection token
39
+ */
45
40
  export declare const NEO4J_DRIVER: InjectionToken<unknown>;
46
- declare const graphRequest: <T>(root: any, params: any, ctx: any, resolveInfo: any) => Promise<T>;
47
- export { graphRequest };
41
+ export declare type NEO4J_DRIVER = Driver;
48
42
  export { Driver } from 'neo4j-driver';
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.graphRequest = exports.NEO4J_DRIVER = exports.NEO4J_MODULE_CONFIG = exports.Neo4JTypes = void 0;
3
+ exports.NEO4J_DRIVER = exports.NEO4J_MODULE_CONFIG = void 0;
4
4
  const core_1 = require("@rxdi/core");
5
- const neo4j_graphql_js_1 = require("neo4j-graphql-js");
6
- exports.Neo4JTypes = new core_1.InjectionToken('GAPI_NEO4J_TYPES');
7
5
  exports.NEO4J_MODULE_CONFIG = new core_1.InjectionToken('GAPI_NEO4J_MODULE_CONFIG');
6
+ /**
7
+ * Neo4j driver @rxdi injection token
8
+ */
8
9
  exports.NEO4J_DRIVER = new core_1.InjectionToken('GAPI_NEO4J_MODULE_CONFIG');
9
- const graphRequest = (root, params, ctx, resolveInfo) => (0, neo4j_graphql_js_1.neo4jgraphql)(root, params, ctx, resolveInfo);
10
- exports.graphRequest = graphRequest;
@@ -1,2 +1 @@
1
- export * from './type.service';
2
1
  export * from './util.service';
@@ -10,5 +10,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./type.service"), exports);
14
13
  __exportStar(require("./util.service"), exports);
@@ -1,14 +1,14 @@
1
- import { NEO4J_MODULE_CONFIG } from '../injection.tokens';
2
- import { GRAPHQL_PLUGIN_CONFIG } from '@rxdi/graphql';
1
+ import { NEO4J_DRIVER, NEO4J_MODULE_CONFIG } from '../injection.tokens';
3
2
  import * as neo4j from 'neo4j-driver';
4
3
  import { GraphQLSchema } from 'graphql';
5
4
  export declare class UtilService {
6
5
  private config;
7
- private gqlConfig;
8
- constructor(config: NEO4J_MODULE_CONFIG, gqlConfig: GRAPHQL_PLUGIN_CONFIG);
6
+ constructor(config: NEO4J_MODULE_CONFIG);
9
7
  private extendSchemaDirectives;
10
8
  private validateSchema;
11
- augmentSchema(schema: GraphQLSchema): GraphQLSchema;
9
+ augmentSchema(schema: GraphQLSchema): (driver: NEO4J_DRIVER) => Promise<GraphQLSchema>;
12
10
  mergeSchemas(...schemas: GraphQLSchema[]): GraphQLSchema;
13
11
  assignDriverToContext(): neo4j.Driver;
12
+ generateTypeDefs(schema: GraphQLSchema): string;
13
+ private findRelations;
14
14
  }
@@ -11,20 +11,26 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
14
23
  Object.defineProperty(exports, "__esModule", { value: true });
15
24
  exports.UtilService = void 0;
16
25
  const core_1 = require("@rxdi/core");
17
- const neo4jgql = require("neo4j-graphql-js");
18
26
  const injection_tokens_1 = require("../injection.tokens");
19
- const graphql_1 = require("@rxdi/graphql");
20
27
  const graphql_tools_1 = require("graphql-tools");
21
28
  const neo4j = require("neo4j-driver");
22
- const generate_type_defs_1 = require("../helpers/generate-type-defs");
29
+ const graphql_1 = require("@neo4j/graphql");
23
30
  const graphql_2 = require("graphql");
24
31
  let UtilService = class UtilService {
25
- constructor(config, gqlConfig) {
32
+ constructor(config) {
26
33
  this.config = config;
27
- this.gqlConfig = gqlConfig;
28
34
  }
29
35
  extendSchemaDirectives(augmentedSchema, schema) {
30
36
  augmentedSchema['_directives'] = schema['_directives'];
@@ -37,11 +43,16 @@ let UtilService = class UtilService {
37
43
  }
38
44
  }
39
45
  augmentSchema(schema) {
40
- this.validateSchema(schema);
41
- return this.extendSchemaDirectives(neo4jgql.makeAugmentedSchema({
42
- typeDefs: (0, generate_type_defs_1.generateTypeDefs)(schema),
43
- config: this.config.excludedTypes
44
- }), schema);
46
+ return (driver) => __awaiter(this, void 0, void 0, function* () {
47
+ this.validateSchema(schema);
48
+ const typeDefs = this.generateTypeDefs(schema);
49
+ const neoSchema = new graphql_1.Neo4jGraphQL({
50
+ typeDefs,
51
+ driver,
52
+ assumeValidSDL: true,
53
+ });
54
+ return this.extendSchemaDirectives(yield neoSchema.getSchema(), schema);
55
+ });
45
56
  }
46
57
  mergeSchemas(...schemas) {
47
58
  return this.extendSchemaDirectives((0, graphql_tools_1.mergeSchemas)({
@@ -49,16 +60,44 @@ let UtilService = class UtilService {
49
60
  }), schemas.filter(s => !!s)[0]);
50
61
  }
51
62
  assignDriverToContext() {
52
- const driver = neo4j.driver(this.config.address || 'bolt://localhost:7687', neo4j.auth.basic(this.config.username, this.config.password));
53
- this.gqlConfig.graphqlOptions.context = this.gqlConfig.graphqlOptions.context || {};
54
- Object.assign(this.gqlConfig.graphqlOptions.context, { driver });
55
- return driver;
63
+ return neo4j.driver(this.config.address || 'bolt://localhost:7687', neo4j.auth.basic(this.config.username, this.config.password));
64
+ }
65
+ 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;
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}`;
89
+ }
90
+ });
91
+ }
92
+ return prev;
93
+ }, {});
94
+ });
95
+ return relations;
56
96
  }
57
97
  };
58
98
  UtilService = __decorate([
59
99
  (0, core_1.Injectable)(),
60
100
  __param(0, (0, core_1.Inject)(injection_tokens_1.NEO4J_MODULE_CONFIG)),
61
- __param(1, (0, core_1.Inject)(graphql_1.GRAPHQL_PLUGIN_CONFIG)),
62
- __metadata("design:paramtypes", [Object, Object])
101
+ __metadata("design:paramtypes", [Object])
63
102
  ], UtilService);
64
103
  exports.UtilService = UtilService;
package/package.json CHANGED
@@ -1,72 +1,72 @@
1
1
  {
2
- "name": "@rxdi/neo4j",
3
- "version": "0.7.152",
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"
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/"
11
52
  ],
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-driver": "^5.0.1",
30
- "neo4j-graphql-js": "^2.19.4"
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.151",
37
- "@rxdi/graphql": "^0.7.151",
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"
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"
47
67
  },
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
- }
68
+ "testRegex": "/src/.*\\.spec.(ts|tsx|js)$",
69
+ "verbose": true,
70
+ "collectCoverage": true
71
+ }
72
72
  }
@@ -1,4 +0,0 @@
1
- import { GraphQLSchema } from 'graphql';
2
- import { RelationshipMap } from '../injection.tokens';
3
- export declare function findRelations(schema: GraphQLSchema): RelationshipMap;
4
- export declare function generateTypeDefs(schema: GraphQLSchema): string;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateTypeDefs = exports.findRelations = void 0;
4
- const graphql_1 = require("graphql");
5
- function findRelations(schema) {
6
- const relations = {};
7
- Object.values(schema.getQueryType()).forEach(field => {
8
- if (!field) {
9
- return;
10
- }
11
- if (typeof field === 'string') {
12
- return;
13
- }
14
- Object.keys(field).reduce((prev, currentType) => {
15
- const type = schema.getType(`${currentType}`);
16
- console.log(type, currentType);
17
- if (type) {
18
- Object.entries(type.getFields()).map(([key, value]) => {
19
- relations[currentType] =
20
- relations[currentType] || {};
21
- const relation = value['relation'];
22
- if (typeof relation === 'object') {
23
- relations[currentType].searchIndex = `${key}: ${value.type}`;
24
- const cyper = relation.cyper ||
25
- `@relation(name: "${relation.name}", direction: "${relation.direction}")`;
26
- relations[currentType].replaceWith = `${relations[currentType].searchIndex} ${cyper}`;
27
- }
28
- });
29
- }
30
- return prev;
31
- }, {});
32
- });
33
- return relations;
34
- }
35
- exports.findRelations = findRelations;
36
- function generateTypeDefs(schema) {
37
- return Object.values(findRelations(schema)).reduce((curr, prev) => curr.replace(prev.searchIndex, prev.replaceWith), (0, graphql_1.printSchema)(schema));
38
- }
39
- exports.generateTypeDefs = generateTypeDefs;
@@ -1,8 +0,0 @@
1
- import { IExcludeType, NEO4J_MODULE_CONFIG } from '../injection.tokens';
2
- export declare const mapToString: (a: IExcludeType[]) => string[];
3
- export declare const exclude: (c: NEO4J_MODULE_CONFIG, type: 'query' | 'mutation', defaultExcludedTypes: IExcludeType[]) => {
4
- [x: string]: {
5
- exclude: IExcludeType[];
6
- };
7
- };
8
- export * from './generate-type-defs';
@@ -1,22 +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
- exports.exclude = exports.mapToString = void 0;
14
- const mapToString = (a) => a.map(t => t.toString());
15
- exports.mapToString = mapToString;
16
- const exclude = (c, type, defaultExcludedTypes) => ({
17
- [type]: {
18
- exclude: defaultExcludedTypes.concat(...c.excludedTypes[type]['exclude'])
19
- }
20
- });
21
- exports.exclude = exclude;
22
- __exportStar(require("./generate-type-defs"), exports);
@@ -1,18 +0,0 @@
1
- import { GraphQLObjectType } from 'graphql';
2
- import { NEO4J_MODULE_CONFIG } from '../injection.tokens';
3
- export declare class TypeService {
4
- private defaultExcludedTypes;
5
- private _registeredTypesMap;
6
- private _registeredTypes;
7
- get types(): GraphQLObjectType<any, any, {
8
- [key: string]: any;
9
- }>[];
10
- getType(type: GraphQLObjectType): GraphQLObjectType<any, any, {
11
- [key: string]: any;
12
- }>;
13
- private addType;
14
- addTypes(types?: GraphQLObjectType[]): GraphQLObjectType<any, any, {
15
- [key: string]: any;
16
- }>[];
17
- extendExcludedTypes(c: NEO4J_MODULE_CONFIG): NEO4J_MODULE_CONFIG;
18
- }
@@ -1,45 +0,0 @@
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.TypeService = void 0;
10
- const core_1 = require("@rxdi/core");
11
- const helpers_1 = require("../helpers");
12
- let TypeService = class TypeService {
13
- constructor() {
14
- this.defaultExcludedTypes = ['Subscription', 'StatusQueryType'];
15
- this._registeredTypesMap = new Map();
16
- this._registeredTypes = [];
17
- }
18
- get types() {
19
- return this._registeredTypes;
20
- }
21
- getType(type) {
22
- return this._registeredTypesMap.get(type.name);
23
- }
24
- addType(type) {
25
- this._registeredTypesMap.set(type.name, type);
26
- this._registeredTypes.push(type);
27
- }
28
- addTypes(types = []) {
29
- types.forEach(type => this.addType(type));
30
- return this._registeredTypes;
31
- }
32
- extendExcludedTypes(c) {
33
- c.excludedTypes = c.excludedTypes || {};
34
- c.excludedTypes.query = c.excludedTypes.query || { exclude: [] };
35
- c.excludedTypes.mutation = c.excludedTypes.mutation || { exclude: [] };
36
- c.excludedTypes = Object.assign(Object.assign({}, (0, helpers_1.exclude)(c, 'mutation', this.defaultExcludedTypes)), (0, helpers_1.exclude)(c, 'query', this.defaultExcludedTypes));
37
- c.excludedTypes.mutation['exclude'] = (0, helpers_1.mapToString)(c.excludedTypes.mutation['exclude']);
38
- c.excludedTypes.mutation['exclude'] = (0, helpers_1.mapToString)(c.excludedTypes.mutation['exclude']);
39
- return c;
40
- }
41
- };
42
- TypeService = __decorate([
43
- (0, core_1.Injectable)()
44
- ], TypeService);
45
- exports.TypeService = TypeService;