@@ -2,22 +2,23 @@ import { Inject, Injectable, Logger } from '@nestjs/common';
2
2
import { isUndefined } from '@nestjs/common/utils/shared.utils' ;
3
3
import {
4
4
ContextIdFactory ,
5
- createContextId ,
6
5
MetadataScanner ,
7
6
ModuleRef ,
8
7
ModulesContainer ,
9
8
REQUEST ,
10
9
} from '@nestjs/core' ;
11
10
import { ExternalContextCreator } from '@nestjs/core/helpers/external-context-creator' ;
12
11
import { ParamMetadata } from '@nestjs/core/helpers/interfaces/params-metadata.interface' ;
13
- import { Injector } from '@nestjs/core/injector/injector' ;
14
12
import { CONTROLLER_ID_KEY } from '@nestjs/core/injector/constants' ;
13
+ import { Injector } from '@nestjs/core/injector/injector' ;
15
14
import {
16
15
ContextId ,
17
16
InstanceWrapper ,
18
17
} from '@nestjs/core/injector/instance-wrapper' ;
19
18
import { InternalCoreModule } from '@nestjs/core/injector/internal-core-module' ;
20
19
import { Module } from '@nestjs/core/injector/module' ;
20
+ import { Entrypoint } from '@nestjs/core/inspector/interfaces/entrypoint.interface' ;
21
+ import { SerializedGraph } from '@nestjs/core/inspector/serialized-graph' ;
21
22
import { REQUEST_CONTEXT_ID } from '@nestjs/core/router/request/request-constants' ;
22
23
import { GraphQLResolveInfo } from 'graphql' ;
23
24
import { head , identity } from 'lodash' ;
@@ -35,21 +36,13 @@ import {
35
36
SUBSCRIPTION_TYPE ,
36
37
} from '../graphql.constants' ;
37
38
import { GqlModuleOptions } from '../interfaces' ;
39
+ import { GqlEntrypointMetadata } from '../interfaces/gql-entrypoint-metadata.interface' ;
38
40
import { ResolverMetadata } from '../interfaces/resolver-metadata.interface' ;
39
- import { getNumberOfArguments } from '../utils' ;
40
41
import { decorateFieldResolverWithMiddleware } from '../utils/decorate-field-resolver.util' ;
41
42
import { extractMetadata } from '../utils/extract-metadata.util' ;
42
43
import { BaseExplorerService } from './base-explorer.service' ;
43
44
import { GqlContextType } from './gql-execution-context' ;
44
45
45
- // TODO remove in the next version (backward-compatibility layer)
46
- // "ContextIdFactory.getByRequest.length" returns an incorrent number
47
- // as parameters with default values do not count in.
48
- // @ref https://github.com/nestjs/graphql/pull/2214
49
- const getByRequestNumberOfArguments = getNumberOfArguments (
50
- ContextIdFactory . getByRequest ,
51
- ) ;
52
-
53
46
@Injectable ( )
54
47
export class ResolversExplorerService extends BaseExplorerService {
55
48
private readonly logger = new Logger ( ResolversExplorerService . name ) ;
@@ -63,6 +56,7 @@ export class ResolversExplorerService extends BaseExplorerService {
63
56
@Inject ( GRAPHQL_MODULE_OPTIONS )
64
57
private readonly gqlOptions : GqlModuleOptions ,
65
58
private readonly moduleRef : ModuleRef ,
59
+ private readonly serializedGraph : SerializedGraph ,
66
60
) {
67
61
super ( ) ;
68
62
}
@@ -113,6 +107,20 @@ export class ResolversExplorerService extends BaseExplorerService {
113
107
. map ( ( resolver ) => {
114
108
this . assignResolverConstructorUniqueId ( instance . constructor , moduleRef ) ;
115
109
110
+ const entrypointDefinition : Entrypoint < GqlEntrypointMetadata > = {
111
+ id : `${ wrapper . id } _${ resolver . methodName } ` ,
112
+ type : 'graphql-entrypoint' ,
113
+ methodName : resolver . methodName ,
114
+ className : wrapper . name ,
115
+ classNodeId : wrapper . id ,
116
+ metadata : {
117
+ key : resolver . name ,
118
+ parentType : resolver . type ,
119
+ } ,
120
+ } ;
121
+
122
+ this . serializedGraph . insertEntrypoint ( entrypointDefinition , wrapper . id ) ;
123
+
116
124
const createContext = ( transform ?: Function ) =>
117
125
this . createContextCallback (
118
126
instance ,
@@ -305,10 +313,7 @@ export class ResolversExplorerService extends BaseExplorerService {
305
313
}
306
314
const wrapper = coreModuleRef . getProviderByKey ( REQUEST ) ;
307
315
wrapper . setInstanceByContextId ( contextId , {
308
- // TODO: remove "as any" in the next major release (backward compatibility)
309
- instance : ( contextId as any ) . getParent
310
- ? ( contextId as any ) . payload
311
- : request ,
316
+ instance : contextId . getParent ? contextId . payload : request ,
312
317
isResolved : true ,
313
318
} ) ;
314
319
}
@@ -346,42 +351,16 @@ export class ResolversExplorerService extends BaseExplorerService {
346
351
}
347
352
348
353
private getContextId ( gqlContext : Record < string | symbol , any > ) : ContextId {
349
- if ( getByRequestNumberOfArguments === 2 ) {
350
- const contextId = ContextIdFactory . getByRequest ( gqlContext , [ 'req' ] ) ;
351
- if ( ! gqlContext [ REQUEST_CONTEXT_ID as any ] ) {
352
- Object . defineProperty ( gqlContext , REQUEST_CONTEXT_ID , {
353
- value : contextId ,
354
- enumerable : false ,
355
- configurable : false ,
356
- writable : false ,
357
- } ) ;
358
- }
359
- return contextId ;
360
- } else {
361
- // TODO remove in the next version (backward-compatibility layer)
362
- // Left for backward compatibility purposes
363
- let contextId : ContextId ;
364
-
365
- if ( gqlContext && gqlContext [ REQUEST_CONTEXT_ID ] ) {
366
- contextId = gqlContext [ REQUEST_CONTEXT_ID ] ;
367
- } else if (
368
- gqlContext &&
369
- gqlContext . req &&
370
- gqlContext . req [ REQUEST_CONTEXT_ID ]
371
- ) {
372
- contextId = gqlContext . req [ REQUEST_CONTEXT_ID ] ;
373
- } else {
374
- contextId = createContextId ( ) ;
375
- Object . defineProperty ( gqlContext , REQUEST_CONTEXT_ID , {
376
- value : contextId ,
377
- enumerable : false ,
378
- configurable : false ,
379
- writable : false ,
380
- } ) ;
381
- }
382
-
383
- return contextId ;
354
+ const contextId = ContextIdFactory . getByRequest ( gqlContext , [ 'req' ] ) ;
355
+ if ( ! gqlContext [ REQUEST_CONTEXT_ID as any ] ) {
356
+ Object . defineProperty ( gqlContext , REQUEST_CONTEXT_ID , {
357
+ value : contextId ,
358
+ enumerable : false ,
359
+ configurable : false ,
360
+ writable : false ,
361
+ } ) ;
384
362
}
363
+ return contextId ;
385
364
}
386
365
387
366
private assignResolverConstructorUniqueId (
0 commit comments