Skip to content

Commit db10842

Browse files
committed
Change ResourcesHost.getByName to handle DB names
1 parent 45c5272 commit db10842

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/core/resources/resources.host.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { CachedByArg, mapKeys } from '@seedcompany/common';
44
import { isObjectType } from 'graphql';
55
import { LazyGetter as Once } from 'lazy-get-decorator';
66
import { mapValues } from 'lodash';
7-
import { ValueOf } from 'type-fest';
87
import {
98
EnhancedResource,
109
InvalidIdForTypeException,
@@ -14,6 +13,7 @@ import {
1413
import { ResourceMap } from './map';
1514
import { __privateDontUseThis } from './resource-map-holder';
1615
import {
16+
AllResourceNames,
1717
ResourceName,
1818
ResourceNameLike,
1919
ResourceStaticFromName,
@@ -52,17 +52,20 @@ export class ResourcesHost {
5252
return mapValues(map, EnhancedResource.of) as any;
5353
}
5454

55-
getByName<K extends keyof ResourceMap>(
56-
name: K,
57-
): EnhancedResource<ValueOf<Pick<ResourceMap, K>>> {
55+
getByName<Name extends AllResourceNames>(
56+
name: Name,
57+
): EnhancedResource<ResourceStaticFromName<ResourceName<Name>>> {
58+
if (name.includes('::')) {
59+
return this.getByEdgeDB(name) as any;
60+
}
5861
const map = this.getEnhancedMap();
59-
const resource = map[name];
62+
const resource = map[name as keyof ResourceMap];
6063
if (!resource) {
6164
throw new ServerException(
6265
`Unable to determine resource from ResourceMap for type: ${name}`,
6366
);
6467
}
65-
return resource;
68+
return resource as any;
6669
}
6770

6871
getByDynamicName(name: ResourceNameLike): EnhancedResource<any> {

0 commit comments

Comments
 (0)