File tree Expand file tree Collapse file tree 2 files changed +47
-9
lines changed Expand file tree Collapse file tree 2 files changed +47
-9
lines changed Original file line number Diff line number Diff line change
1
+ import { GraphQLSchemaHost } from '@nestjs/graphql' ;
2
+ import { EnhancedResourceMap } from '~/core' ;
3
+ import { ResourcesHost } from './resources.host' ;
4
+
5
+ describe ( 'ResourcesHost' , ( ) => {
6
+ let host : ResourcesHost ;
7
+ let all : EnhancedResourceMap ;
8
+
9
+ beforeAll ( async ( ) => {
10
+ // Load all files to ensure all resources are registered
11
+ await import ( '../../app.module' ) ;
12
+
13
+ host = new ResourcesHost ( new GraphQLSchemaHost ( ) ) ;
14
+ all = await host . getEnhancedMap ( ) ;
15
+ } ) ;
16
+
17
+ describe ( 'By EdgeDB' , ( ) => {
18
+ it ( 'FQN' , async ( ) => {
19
+ const res = await host . getByEdgeDB ( 'default::User' ) ;
20
+ expect ( res ) . toBeDefined ( ) ;
21
+ expect ( res ) . toBe ( all . User ) ;
22
+ } ) ;
23
+ it ( 'Implicit default module' , async ( ) => {
24
+ const res = await host . getByEdgeDB ( 'User' ) ;
25
+ expect ( res ) . toBe ( all . User ) ;
26
+ } ) ;
27
+ it ( 'GQL Name different from FQN' , async ( ) => {
28
+ const res = await host . getByEdgeDB ( 'Ceremony' ) ;
29
+ expect ( res ) . toBe ( all . Ceremony ) ;
30
+ } ) ;
31
+ } ) ;
32
+ } ) ;
Original file line number Diff line number Diff line change @@ -68,17 +68,23 @@ export class ResourcesHost {
68
68
}
69
69
70
70
async getByEdgeDB (
71
- fqn : string ,
71
+ name : string ,
72
72
) : Promise < EnhancedResource < ValueOf < ResourceMap > > > {
73
- fqn = fqn . includes ( '::' ) ? fqn : `default::${ fqn } ` ;
74
- const map = await this . edgeDBFQNMap ( ) ;
75
- const resource = map . get ( fqn ) ;
76
- if ( ! resource ) {
77
- throw new ServerException (
78
- `Unable to determine resource from ResourceMap for EdgeDB FQN: ${ fqn } ` ,
79
- ) ;
73
+ const fqnMap = await this . edgeDBFQNMap ( ) ;
74
+ const resByFQN = fqnMap . get (
75
+ name . includes ( '::' ) ? name : `default::${ name } ` ,
76
+ ) ;
77
+ if ( resByFQN ) {
78
+ return resByFQN ;
80
79
}
81
- return resource ;
80
+ const nameMap = await this . getEnhancedMap ( ) ;
81
+ const resByName = nameMap [ name as keyof ResourceMap ] ;
82
+ if ( resByName ) {
83
+ return resByName as any ;
84
+ }
85
+ throw new ServerException (
86
+ `Unable to determine resource from ResourceMap for EdgeDB FQN: ${ name } ` ,
87
+ ) ;
82
88
}
83
89
84
90
@CachedByArg ( )
You can’t perform that action at this time.
0 commit comments