-
Hi, I'm using pothos to write a library, for context of the below code please see here: https://github.com/m1212e/rumble/blob/2a5e9ff1f9f89ab5141f8f673ee17e734b103b1c/lib/gql/builder.ts#L91 I'm getting this error: This is what I'm trying to do. Basically it is a helper function to implement drizzle objects based on a drizzle schema automatically. const implementDefaultObject = <
ExplicitTableName extends Parameters<typeof nativeBuilder.drizzleObject>[0],
RefName extends string,
>({
tableName,
name,
readAction = "read" as Action,
}: {
tableName: ExplicitTableName;
name: RefName;
readAction?: Action;
}) => {
const schema = db._.schema![tableName];
return nativeBuilder.drizzleObject(tableName, {
name,
fields: (t) => {
const mapSQLTypeStringToExposedPothosType = (
sqlType: string,
columnName: string,
) => {
switch (sqlType) {
case "serial":
// @ts-expect-error
return t.exposeInt(columnName);
case "int":
// @ts-expect-error
return t.exposeInt(columnName);
case "string":
// @ts-expect-error
return t.exposeString(columnName);
case "text":
// @ts-expect-error
return t.exposeString(columnName);
case "boolean":
// @ts-expect-error
return t.exposeBoolean(columnName);
default:
throw new RumbleError(
`Unknown SQL type: ${sqlType}. Please open an issue so it can be added.`,
);
}
};
const fields = Object.entries(schema.columns).reduce(
(acc, [key, value]) => {
acc[key] = mapSQLTypeStringToExposedPothosType(
value.getSQLType(),
value.name,
);
return acc;
},
{} as Record<
string,
ReturnType<typeof mapSQLTypeStringToExposedPothosType>
>,
);
const relations = Object.entries(schema.relations).reduce(
(acc, [key, value]) => {
acc[key] = t.relation(key, {
query: (_args: any, ctx: any) =>
ctx.abilities[tableName].filter(readAction),
} as any) as any;
return acc;
},
{} as Record<
string,
ReturnType<typeof mapSQLTypeStringToExposedPothosType>
>,
);
return {
...fields,
...relations,
};
},
});
}; Do you happen to know what causes this? Thank you so much for your time and work! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Moved to issue #1370 |
Beta Was this translation helpful? Give feedback.
Moved to issue #1370