Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spread operator incorrect type generation #1253

Closed
2 tasks done
zane-atomus opened this issue Jul 26, 2024 · 3 comments
Closed
2 tasks done

Spread operator incorrect type generation #1253

zane-atomus opened this issue Jul 26, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@zane-atomus
Copy link

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When joining a related one-to-one table using the ... spread operator, the type generation assumes that the rows exist in the related table and does not have null as an option for the child table column values, however the returned data has null values for rows where the row is missing.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a table parent with an id column as the primary key.
  2. Create a table (child) with a foreign key relationship to parent (id) (we'll call this column parent_id), and a constraint unique (parent_id). For the example we will add two columns col_1, col_2 which have type boolean and are not null.
  3. Run a query with supabase-js with the spread operator const { data, error } = db.from("parent").select("id,...child(col_1,col_2).

Expected behavior

Since the child row might not exist for a given parent row, the type of data should be:

{
    id: string;
    col_1: boolean | null;
    col_2: boolean | null;
}

instead it gives:

{
    id: string;
    col_1: boolean;
    col_2: boolean;
}

The returned data contains null values as expected which makes the typing inaccurate.

System information

  • OS: macOS
  • Version of supabase-js: 2.44.1
  • Version of Node.js: 20.12.1
@zane-atomus zane-atomus added the bug Something isn't working label Jul 26, 2024
@avallete
Copy link
Member

Hey there !

We've reworked the result inference in postgrest-js to address the typing issues mentioned above. The changes are available in a canary release, and we're actively seeking your feedback.

To test it out, update your supabase-js to version 2.46.0-rc.1 (which includes postgrest-js 1.17.0-rc.1):

npm install [email protected]

@zane-atomus
Copy link
Author

Hey there !

We've reworked the result inference in postgrest-js to address the typing issues mentioned above. The changes are available in a canary release, and we're actively seeking your feedback.

To test it out, update your supabase-js to version 2.46.0-rc.1 (which includes postgrest-js 1.17.0-rc.1):

npm install [email protected]

Hi,

From our initial testing, our queries appear to be generating the expected return types now! Looking forward to the release of this version.

@avallete
Copy link
Member

The fix has been released in supabase-js v2.46.0. I'm closing this issue, but feel free to reopen if you encounter any further errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants