Skip to content

Commit 9028ad7

Browse files
authored
[EdgeDB] Fix getBaseNode not using the right type name in some cases (#3054)
1 parent 6e1bd8d commit 9028ad7

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
});

src/core/resources/resources.host.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,23 @@ export class ResourcesHost {
6868
}
6969

7070
async getByEdgeDB(
71-
fqn: string,
71+
name: string,
7272
): 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;
8079
}
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+
);
8288
}
8389

8490
@CachedByArg()

0 commit comments

Comments
 (0)