-
-
Notifications
You must be signed in to change notification settings - Fork 474
Description
Bug report
Describe the bug
Typings are not correct when joining tables that are always NOT an array. For example, in my application we use the following query to fetch data about figma_comments
and link to figma_users
and figma_files
:
const { data: comments } = await supabase
.from('figma_comments')
.select(
'created_at, resolved_at, comment, node_id, user:figma_users(handle, img_url, email), file:figma_files(file_key, name)',
)
.order('created_at', { ascending: false });
From this query, I would expect the built in typings to have both user
and file
to be an entity of a singular user and a singular file. Since the constraints I set up in Postgres won’t allow it to be multiple entries because the foreign key is unique on the joinable tables.
Here is an overview of the types being generated by supabase CLI:
Tables: {
figma_comments: {
Row: {
comment: string;
created_at: string;
figma_user_id: string;
file_key: string;
id: number;
node_id: string;
order_id: number | null;
parent_id: string | null;
resolved_at: string | null;
};
Insert: {
comment: string;
created_at?: string;
figma_user_id: string;
file_key: string;
id?: number;
node_id: string;
order_id?: number | null;
parent_id?: string | null;
resolved_at?: string | null;
};
Update: {
comment?: string;
created_at?: string;
figma_user_id?: string;
file_key?: string;
id?: number;
node_id?: string;
order_id?: number | null;
parent_id?: string | null;
resolved_at?: string | null;
};
};
figma_files: {
Row: {
editor_type: string | null;
figma_project_id: number | null;
file_key: string;
id: number;
last_modified: string;
name: string;
thumbnail_url: string;
version: string | null;
};
Insert: {
editor_type?: string | null;
figma_project_id?: number | null;
file_key: string;
id?: number;
last_modified: string;
name: string;
thumbnail_url: string;
version?: string | null;
};
Update: {
editor_type?: string | null;
figma_project_id?: number | null;
file_key?: string;
id?: number;
last_modified?: string;
name?: string;
thumbnail_url?: string;
version?: string | null;
};
};
figma_users: {
Row: {
email: string;
figma_id: string;
handle: string;
id: number;
img_url: string;
};
Insert: {
email: string;
figma_id: string;
handle: string;
id?: number;
img_url: string;
};
Update: {
email?: string;
figma_id?: string;
handle?: string;
id?: number;
img_url?: string;
};
};
};
Expected behavior
I would expect the built in typings to know that user and file in the case of my query is an object if the entity, not an array of objects. This is because figma_files.file_key
and figma_users.figma_id
are set to UNIQUE.
I understand that making this work might be extremely difficult, but does anyone have any suggestions on how to make the typings work for me so I do not have to cast these types?
System information
- OS: macOS
- Version of supabase-js: 2.10.0
- Version of Node.js: v16.13.0