Skip to content

Commit ca65518

Browse files
committed
Fix query builder rendering luxon objects with range functions (patching castMaps)
1 parent 6a1f922 commit ca65518

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/core/edgedb/generator/query-builder.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export async function generateQueryBuilder({
2323
addJsExtensionDeepPathsOfEdgedbLibrary(qbDir);
2424
changeCustomScalars(qbDir);
2525
updateEdgeQLRenderingForOurCustomScalars(qbDir);
26+
updateCastMapsForOurCustomScalars(qbDir);
2627
changeImplicitIDType(qbDir);
2728
allowOrderingByEnums(qbDir);
2829
mergeDefaultTypesWithModuleNames(qbDir);
@@ -67,6 +68,40 @@ function changeImplicitIDType(qbDir: Directory) {
6768
);
6869
}
6970

71+
function updateCastMapsForOurCustomScalars(qbDir: Directory) {
72+
const file = qbDir.addSourceFileAtPath('castMaps.ts');
73+
file.insertImportDeclaration(1, {
74+
namedImports: ['DateTime'],
75+
moduleSpecifier: 'luxon',
76+
});
77+
file.insertImportDeclaration(1, {
78+
namedImports: ['CalendarDate'],
79+
moduleSpecifier: '~/common',
80+
leadingTrivia: '\n',
81+
});
82+
const updated = file
83+
.getText()
84+
// Update Luxon instances to point to correct scalar UUIDs
85+
.replace(
86+
'(type instanceof Date)',
87+
'(type instanceof Date || (type instanceof DateTime && !(type instanceof CalendarDate)))',
88+
)
89+
.replace(
90+
'(type instanceof edgedb.LocalDate)',
91+
'(type instanceof edgedb.LocalDate || type instanceof CalendarDate)',
92+
);
93+
// Attempting to pick the right type based on shape.
94+
// This doesn't fix any errors, and currently we are unable to distinguish
95+
// CalendarDate from DateTime based on shape since they are the same.
96+
// import * as _std from '../generated-client/modules/std';
97+
// .replace(
98+
// ' T extends Date ? scalarWithConstType<_std.$datetime, T> :\n',
99+
// ' T extends CalendarDate ? scalarWithConstType<_cal.$local_date, T> :\n' +
100+
// ' T extends Date | DateTime ? scalarWithConstType<_std.$datetime, T> :\n',
101+
// )
102+
file.replaceWithText(updated);
103+
}
104+
70105
function updateEdgeQLRenderingForOurCustomScalars(qbDir: Directory) {
71106
const file = qbDir.addSourceFileAtPath('toEdgeQL.ts');
72107
file.insertImportDeclaration(1, {

0 commit comments

Comments
 (0)