@rxdi/neo4j 0.7.152 → 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/README.md +49 -217
- package/dist/index.d.ts +1 -2
- package/dist/index.js +18 -33
- package/dist/injection.tokens.d.ts +15 -33
- package/dist/injection.tokens.js +20 -6
- package/dist/neo4j.service.d.ts +15 -0
- package/dist/neo4j.service.js +115 -0
- package/package.json +5 -5
- package/dist/helpers/generate-type-defs.d.ts +0 -4
- package/dist/helpers/generate-type-defs.js +0 -39
- package/dist/helpers/index.d.ts +0 -8
- package/dist/helpers/index.js +0 -22
- package/dist/services/index.d.ts +0 -2
- package/dist/services/index.js +0 -14
- package/dist/services/type.service.d.ts +0 -18
- package/dist/services/type.service.js +0 -45
- package/dist/services/util.service.d.ts +0 -14
- package/dist/services/util.service.js +0 -64
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
[](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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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 './
|
|
7
|
+
export * from './neo4j.service';
|
package/dist/index.js
CHANGED
|
@@ -15,51 +15,37 @@ 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
|
-
const
|
|
26
|
-
const rxjs_1 = require("rxjs");
|
|
27
|
-
const operators_1 = require("rxjs/operators");
|
|
33
|
+
const neo4j_service_1 = require("./neo4j.service");
|
|
28
34
|
let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
|
|
29
35
|
static forRoot(config = {}) {
|
|
30
36
|
return {
|
|
31
37
|
module: Neo4JModule_1,
|
|
32
38
|
providers: [
|
|
39
|
+
neo4j_service_1.UtilService,
|
|
33
40
|
{
|
|
34
41
|
provide: injection_tokens_1.NEO4J_MODULE_CONFIG,
|
|
35
42
|
useValue: config
|
|
36
43
|
},
|
|
37
44
|
{
|
|
38
|
-
provide: injection_tokens_1.
|
|
39
|
-
deps: [
|
|
40
|
-
|
|
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)
|
|
45
|
+
provide: injection_tokens_1.NEO4J_DRIVER,
|
|
46
|
+
deps: [neo4j_service_1.UtilService],
|
|
47
|
+
useFactory: (util) => util.createDriver()
|
|
47
48
|
},
|
|
48
|
-
...(config.onRequest
|
|
49
|
-
? [
|
|
50
|
-
{
|
|
51
|
-
provide: graphql_1.ON_REQUEST_HANDLER,
|
|
52
|
-
deps: [injection_tokens_1.NEO4J_MODULE_CONFIG],
|
|
53
|
-
useFactory: (config) => config.onRequest
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
: [
|
|
57
|
-
{
|
|
58
|
-
provide: injection_tokens_1.NEO4J_DRIVER,
|
|
59
|
-
deps: [util_service_1.UtilService],
|
|
60
|
-
useFactory: (util) => util.assignDriverToContext()
|
|
61
|
-
}
|
|
62
|
-
]),
|
|
63
49
|
...(config.schemaOverride
|
|
64
50
|
? [
|
|
65
51
|
{
|
|
@@ -70,20 +56,19 @@ let Neo4JModule = Neo4JModule_1 = class Neo4JModule {
|
|
|
70
56
|
: [
|
|
71
57
|
{
|
|
72
58
|
provide: graphql_1.SCHEMA_OVERRIDE,
|
|
73
|
-
deps: [
|
|
74
|
-
useFactory: (util) => (schema) => util.augmentSchema(schema)
|
|
59
|
+
deps: [neo4j_service_1.UtilService, injection_tokens_1.NEO4J_DRIVER],
|
|
60
|
+
useFactory: (util, driver) => (schema) => __awaiter(this, void 0, void 0, function* () { return util.augmentSchema(schema)(driver); })
|
|
75
61
|
}
|
|
76
62
|
])
|
|
77
63
|
]
|
|
78
64
|
};
|
|
79
65
|
}
|
|
80
|
-
static forChild(types) { }
|
|
81
66
|
};
|
|
82
67
|
Neo4JModule = Neo4JModule_1 = __decorate([
|
|
83
68
|
(0, core_1.Module)({
|
|
84
|
-
providers: [
|
|
69
|
+
providers: [neo4j_service_1.UtilService]
|
|
85
70
|
})
|
|
86
71
|
], Neo4JModule);
|
|
87
72
|
exports.Neo4JModule = Neo4JModule;
|
|
88
73
|
__exportStar(require("./injection.tokens"), exports);
|
|
89
|
-
__exportStar(require("./
|
|
74
|
+
__exportStar(require("./neo4j.service"), exports);
|
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
import { InjectionToken } from '@rxdi/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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[];
|
|
2
|
+
import { GraphQLSchema } from 'graphql';
|
|
3
|
+
import { Driver } from 'neo4j-driver';
|
|
11
4
|
export declare const NEO4J_MODULE_CONFIG: InjectionToken<NEO4J_MODULE_CONFIG>;
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
query?: {
|
|
18
|
-
exclude: IExcludeType[];
|
|
19
|
-
};
|
|
5
|
+
export interface NEO4J_MODULE_CONFIG {
|
|
6
|
+
username?: string;
|
|
7
|
+
password?: string;
|
|
8
|
+
address?: string | 'bolt://localhost:7687';
|
|
9
|
+
schemaOverride?(schema: GraphQLSchema): GraphQLSchema;
|
|
20
10
|
}
|
|
21
11
|
export interface RelationshipType {
|
|
22
|
-
searchIndex
|
|
23
|
-
replaceWith
|
|
12
|
+
searchIndex?: string;
|
|
13
|
+
replaceWith?: string;
|
|
14
|
+
extends?: string;
|
|
24
15
|
}
|
|
25
16
|
export interface Relationship {
|
|
26
17
|
direction: 'IN' | 'OUT';
|
|
@@ -30,19 +21,10 @@ export interface Relationship {
|
|
|
30
21
|
export interface RelationshipMap {
|
|
31
22
|
[key: string]: RelationshipType;
|
|
32
23
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
password?: string;
|
|
37
|
-
address?: string | 'bolt://localhost:7687';
|
|
38
|
-
excludedTypes?: AugmentSchemaConfig;
|
|
39
|
-
debug?: boolean;
|
|
40
|
-
auth?: boolean;
|
|
41
|
-
context?: any;
|
|
42
|
-
onRequest?(next: any, request: Request, h: ResponseToolkit, err: Error): Promise<any>;
|
|
43
|
-
schemaOverride?(schema: GraphQLSchema): GraphQLSchema;
|
|
44
|
-
}
|
|
24
|
+
/**
|
|
25
|
+
* Neo4j driver @rxdi injection token
|
|
26
|
+
*/
|
|
45
27
|
export declare const NEO4J_DRIVER: InjectionToken<unknown>;
|
|
46
|
-
declare
|
|
47
|
-
export { graphRequest };
|
|
28
|
+
export declare type NEO4J_DRIVER = Driver;
|
|
48
29
|
export { Driver } from 'neo4j-driver';
|
|
30
|
+
export declare function gql(...args: any[]): any;
|
package/dist/injection.tokens.js
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.gql = 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');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Neo4j driver @rxdi injection token
|
|
8
|
+
*/
|
|
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;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NEO4J_DRIVER, NEO4J_MODULE_CONFIG } from './injection.tokens';
|
|
2
|
+
import * as neo4j from 'neo4j-driver';
|
|
3
|
+
import { GraphQLSchema } from 'graphql';
|
|
4
|
+
export declare class UtilService {
|
|
5
|
+
private config;
|
|
6
|
+
constructor(config: NEO4J_MODULE_CONFIG);
|
|
7
|
+
private extendSchemaDirectives;
|
|
8
|
+
private validateSchema;
|
|
9
|
+
private replaceAll;
|
|
10
|
+
augmentSchema(schema: GraphQLSchema): (driver: NEO4J_DRIVER) => Promise<GraphQLSchema>;
|
|
11
|
+
mergeSchemas(...schemas: GraphQLSchema[]): GraphQLSchema;
|
|
12
|
+
createDriver(): neo4j.Driver;
|
|
13
|
+
generateTypeDefs(schema: GraphQLSchema): string;
|
|
14
|
+
private findSchemaExtensions;
|
|
15
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
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
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.UtilService = void 0;
|
|
25
|
+
const core_1 = require("@rxdi/core");
|
|
26
|
+
const injection_tokens_1 = require("./injection.tokens");
|
|
27
|
+
const graphql_tools_1 = require("graphql-tools");
|
|
28
|
+
const neo4j = require("neo4j-driver");
|
|
29
|
+
const graphql_1 = require("@neo4j/graphql");
|
|
30
|
+
const graphql_2 = require("graphql");
|
|
31
|
+
let UtilService = class UtilService {
|
|
32
|
+
constructor(config) {
|
|
33
|
+
this.config = config;
|
|
34
|
+
}
|
|
35
|
+
extendSchemaDirectives(augmentedSchema, schema) {
|
|
36
|
+
augmentedSchema['_directives'] = schema['_directives'];
|
|
37
|
+
return augmentedSchema;
|
|
38
|
+
}
|
|
39
|
+
validateSchema(schema) {
|
|
40
|
+
const schemaErrors = (0, graphql_2.validateSchema)(schema);
|
|
41
|
+
if (schemaErrors.length) {
|
|
42
|
+
throw new Error(JSON.stringify(schemaErrors));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
replaceAll(value) {
|
|
46
|
+
return (search) => (replacement) => value.split(search).join(replacement);
|
|
47
|
+
}
|
|
48
|
+
augmentSchema(schema) {
|
|
49
|
+
return (driver) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
this.validateSchema(schema);
|
|
51
|
+
const typeDefs = this.generateTypeDefs(schema);
|
|
52
|
+
const neoSchema = new graphql_1.Neo4jGraphQL({
|
|
53
|
+
typeDefs,
|
|
54
|
+
driver,
|
|
55
|
+
assumeValidSDL: true,
|
|
56
|
+
});
|
|
57
|
+
const augmentedSchema = yield neoSchema.getSchema();
|
|
58
|
+
return this.extendSchemaDirectives(augmentedSchema, schema);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
mergeSchemas(...schemas) {
|
|
62
|
+
return this.extendSchemaDirectives((0, graphql_tools_1.mergeSchemas)({
|
|
63
|
+
schemas: schemas.filter(s => !!s)
|
|
64
|
+
}), schemas.filter(s => !!s)[0]);
|
|
65
|
+
}
|
|
66
|
+
createDriver() {
|
|
67
|
+
return neo4j.driver(this.config.address || 'bolt://localhost:7687', neo4j.auth.basic(this.config.username, this.config.password));
|
|
68
|
+
}
|
|
69
|
+
generateTypeDefs(schema) {
|
|
70
|
+
return Object.values(this.findSchemaExtensions(schema)).reduce((curr, prev) => {
|
|
71
|
+
if (prev.extends) {
|
|
72
|
+
return `${curr}\n${prev.extends}`;
|
|
73
|
+
}
|
|
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
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return prev;
|
|
104
|
+
}, {});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return extensions;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
UtilService = __decorate([
|
|
111
|
+
(0, core_1.Injectable)(),
|
|
112
|
+
__param(0, (0, core_1.Inject)(injection_tokens_1.NEO4J_MODULE_CONFIG)),
|
|
113
|
+
__metadata("design:paramtypes", [Object])
|
|
114
|
+
], UtilService);
|
|
115
|
+
exports.UtilService = UtilService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdi/neo4j",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.154",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/rxdi/neo4j/blob/master/README.md",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"neo4j
|
|
30
|
-
"neo4j-
|
|
29
|
+
"@neo4j/graphql": "^3.8.0",
|
|
30
|
+
"neo4j-driver": "^5.0.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"graphql": "^14.5.8",
|
|
34
34
|
"@types/graphql": "^14.5.0",
|
|
35
35
|
"graphql-tools": "^5.0.0",
|
|
36
|
-
"@rxdi/core": "^0.7.
|
|
37
|
-
"@rxdi/graphql": "^0.7.
|
|
36
|
+
"@rxdi/core": "^0.7.153",
|
|
37
|
+
"@rxdi/graphql": "^0.7.153",
|
|
38
38
|
"@types/hapi": "^18.0.4",
|
|
39
39
|
"@types/jest": "^24.0.22",
|
|
40
40
|
"@types/node": "^12.0.10",
|
|
@@ -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;
|
package/dist/helpers/index.d.ts
DELETED
|
@@ -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';
|
package/dist/helpers/index.js
DELETED
|
@@ -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);
|
package/dist/services/index.d.ts
DELETED
package/dist/services/index.js
DELETED
|
@@ -1,14 +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("./type.service"), exports);
|
|
14
|
-
__exportStar(require("./util.service"), 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;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { NEO4J_MODULE_CONFIG } from '../injection.tokens';
|
|
2
|
-
import { GRAPHQL_PLUGIN_CONFIG } from '@rxdi/graphql';
|
|
3
|
-
import * as neo4j from 'neo4j-driver';
|
|
4
|
-
import { GraphQLSchema } from 'graphql';
|
|
5
|
-
export declare class UtilService {
|
|
6
|
-
private config;
|
|
7
|
-
private gqlConfig;
|
|
8
|
-
constructor(config: NEO4J_MODULE_CONFIG, gqlConfig: GRAPHQL_PLUGIN_CONFIG);
|
|
9
|
-
private extendSchemaDirectives;
|
|
10
|
-
private validateSchema;
|
|
11
|
-
augmentSchema(schema: GraphQLSchema): GraphQLSchema;
|
|
12
|
-
mergeSchemas(...schemas: GraphQLSchema[]): GraphQLSchema;
|
|
13
|
-
assignDriverToContext(): neo4j.Driver;
|
|
14
|
-
}
|
|
@@ -1,64 +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
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.UtilService = void 0;
|
|
16
|
-
const core_1 = require("@rxdi/core");
|
|
17
|
-
const neo4jgql = require("neo4j-graphql-js");
|
|
18
|
-
const injection_tokens_1 = require("../injection.tokens");
|
|
19
|
-
const graphql_1 = require("@rxdi/graphql");
|
|
20
|
-
const graphql_tools_1 = require("graphql-tools");
|
|
21
|
-
const neo4j = require("neo4j-driver");
|
|
22
|
-
const generate_type_defs_1 = require("../helpers/generate-type-defs");
|
|
23
|
-
const graphql_2 = require("graphql");
|
|
24
|
-
let UtilService = class UtilService {
|
|
25
|
-
constructor(config, gqlConfig) {
|
|
26
|
-
this.config = config;
|
|
27
|
-
this.gqlConfig = gqlConfig;
|
|
28
|
-
}
|
|
29
|
-
extendSchemaDirectives(augmentedSchema, schema) {
|
|
30
|
-
augmentedSchema['_directives'] = schema['_directives'];
|
|
31
|
-
return augmentedSchema;
|
|
32
|
-
}
|
|
33
|
-
validateSchema(schema) {
|
|
34
|
-
const schemaErrors = (0, graphql_2.validateSchema)(schema);
|
|
35
|
-
if (schemaErrors.length) {
|
|
36
|
-
throw new Error(JSON.stringify(schemaErrors));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
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);
|
|
45
|
-
}
|
|
46
|
-
mergeSchemas(...schemas) {
|
|
47
|
-
return this.extendSchemaDirectives((0, graphql_tools_1.mergeSchemas)({
|
|
48
|
-
schemas: schemas.filter(s => !!s)
|
|
49
|
-
}), schemas.filter(s => !!s)[0]);
|
|
50
|
-
}
|
|
51
|
-
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;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
UtilService = __decorate([
|
|
59
|
-
(0, core_1.Injectable)(),
|
|
60
|
-
__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])
|
|
63
|
-
], UtilService);
|
|
64
|
-
exports.UtilService = UtilService;
|