Skip to content

Commit adbf33d

Browse files
fix(engine, codegen): relation resolver types
1 parent bdd21e2 commit adbf33d

File tree

5 files changed

+320
-25
lines changed

5 files changed

+320
-25
lines changed

packages/codegen/src/generate.spec.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ const schema = `
1313
define owner: [user]
1414
`;
1515

16+
const relationSchema = `
17+
type user
18+
19+
type team
20+
relations
21+
define member: [user]
22+
23+
type repository
24+
relations
25+
define team: [team]
26+
define viewer: member from team
27+
`;
28+
1629
describe("generateTypeScript", () => {
1730
test("generates base helper types from schema", async () => {
1831
const result = await generateTypeScript({ schema });
@@ -24,7 +37,15 @@ describe("generateTypeScript", () => {
2437
expect(result.content).toContain("user: unknown;");
2538
expect(result.content).toContain("repository: unknown;");
2639
expect(result.content).toContain('repository: "owner";');
27-
expect(result.content).toContain("createGeneratedEngine");
40+
expect(result.content).toContain(
41+
"export interface GraplixRelationTargetTypeNamesByType {",
42+
);
43+
expect(result.content).toContain('owner: "user";');
44+
expect(result.content).toContain(
45+
"export type GraplixResolveTypeValue = unknown;",
46+
);
47+
expect(result.content).toContain("value: GraplixResolveTypeValue,");
48+
expect(result.content).toContain("export function createEngine");
2849
});
2950

3051
test("supports mapper imports and mapper type binding", async () => {
@@ -44,6 +65,19 @@ describe("generateTypeScript", () => {
4465
);
4566
expect(result.content).toContain("user: Mapper_user;");
4667
expect(result.content).toContain("repository: Mapper_repository;");
68+
expect(result.content).toContain(
69+
"export type GraplixResolveTypeValue = GraplixProvidedMapperTypes[keyof GraplixProvidedMapperTypes];",
70+
);
71+
});
72+
73+
test("infers relation target types across source relations", async () => {
74+
const result = await generateTypeScript({ schema: relationSchema });
75+
76+
expect(result.content).toContain("repository: {");
77+
expect(result.content).toContain('viewer: "user";');
78+
expect(result.content).toContain(
79+
"keyof GraplixRelationTargetTypeNamesByType[TTypeName]",
80+
);
4781
});
4882

4983
test("generates from .graplix file path", async () => {

0 commit comments

Comments
 (0)