Skip to content

Commit

Permalink
Allow scalarToLiteralMapping to declare TS type for custom scalar (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF authored Jan 12, 2024
1 parent ead4189 commit c991a82
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
20 changes: 4 additions & 16 deletions packages/generate/src/edgeql-js/generateInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,10 @@ export const generateInterfaces = (params: GenerateInterfacesParams) => {
} else if (isLink) {
return getTypeName(targetType.name);
} else {
const baseType =
targetType.kind === "scalar"
? (targetType.bases
.map(({ id }) => types.get(id))
.filter(
(base) => !base.is_abstract
)[0] as $.introspect.ScalarType)
: null;
return toTSScalarType(
baseType ?? (targetType as $.introspect.PrimitiveType),
types,
{
getEnumRef: (enumType) => getTypeName(enumType.name),
edgedbDatatypePrefix: "",
}
).join("");
return toTSScalarType(targetType as $.introspect.PrimitiveType, types, {
getEnumRef: (enumType) => getTypeName(enumType.name),
edgedbDatatypePrefix: "",
}).join("");
}
};

Expand Down
5 changes: 1 addition & 4 deletions packages/generate/src/edgeql-js/generateScalars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ export const generateScalars = (params: GeneratorParams) => {
}

// generate non-enum non-abstract scalar
const baseType = type.bases
.map(({ id }) => types.get(id))
.filter((base) => !base.is_abstract)[0] as $.introspect.ScalarType;
const tsType = toTSScalarType(baseType ?? type, types);
const tsType = toTSScalarType(type, types);
// const tsType = toTSScalarType(type, types);
// const extraTypes = scalarToLiteralMapping[type.name]?.extraTypes;
// const extraTypesUnion = extraTypes ? `, ${extraTypes.join(" | ")}` : "";
Expand Down
2 changes: 1 addition & 1 deletion packages/generate/src/genutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function toTSScalarType(
return [getRef(type.name, { prefix: "" })];
}

if (type.material_id) {
if (type.material_id && !scalarToLiteralMapping[type.name]) {
return toTSScalarType(
types.get(type.material_id) as introspect.ScalarType,
types,
Expand Down

0 comments on commit c991a82

Please sign in to comment.