@@ -4,7 +4,12 @@ import { LazyGetter as Once } from 'lazy-get-decorator';
4
4
import { DateTime } from 'luxon' ;
5
5
import { keys as keysOf } from 'ts-transformer-keys' ;
6
6
import { inspect } from 'util' ;
7
- import type { ResourceDBMap , ResourceName } from '~/core' ;
7
+ import type {
8
+ ResourceDBMap ,
9
+ ResourceLike ,
10
+ ResourceName ,
11
+ ResourcesHost ,
12
+ } from '~/core' ;
8
13
import { $ , e } from '~/core/edgedb/reexports' ;
9
14
import { ScopedRole } from '../components/authorization/dto' ;
10
15
import { CalculatedSymbol } from './calculated.decorator' ;
@@ -27,7 +32,7 @@ const hasTypename = (value: unknown): value is { __typename: string } =>
27
32
export const resolveByTypename =
28
33
( interfaceName : string ) => ( value : unknown ) => {
29
34
if ( hasTypename ( value ) ) {
30
- return value . __typename ;
35
+ return EnhancedResource . resolve ( value . __typename ) . name ;
31
36
}
32
37
throw new ServerException ( `Cannot resolve ${ interfaceName } type` ) ;
33
38
} ;
@@ -87,13 +92,22 @@ export class EnhancedResource<T extends ResourceShape<any>> {
87
92
static readonly dbTypes = new WeakMap < ResourceShape < any > , $ . $expr_PathNode > ( ) ;
88
93
/** @internal */
89
94
static readonly dbSkipAccessPolicies = new Set < string > ( ) ;
95
+ /** @internal */
96
+ static resourcesHost ?: ResourcesHost ;
90
97
91
98
private constructor ( readonly type : T ) { }
92
99
private static readonly refs = new WeakMap <
93
100
ResourceShape < any > ,
94
101
EnhancedResource < any >
95
102
> ( ) ;
96
103
104
+ static resolve ( ref : ResourceLike ) {
105
+ if ( ! EnhancedResource . resourcesHost ) {
106
+ throw new ServerException ( 'Cannot resolve without ResourcesHost' ) ;
107
+ }
108
+ return EnhancedResource . resourcesHost . enhance ( ref ) ;
109
+ }
110
+
97
111
static of < T extends ResourceShape < any > > (
98
112
resource : T | EnhancedResource < T > ,
99
113
) : EnhancedResource < T > {
0 commit comments