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

fix(select-query-parser): select left join and array instead of objects result types #553

Merged

Conversation

avallete
Copy link
Member

@avallete avallete commented Sep 8, 2024

What kind of change does this PR introduce?

This PR improves the TypeScript typings generated by the SQL query parser, fixing issues with inferred types for certain !left joins and relationship queries (e.g., created_by:users(*)).

What is the current behavior?

Currently, for certain queries, the inferred types for relations are incorrect. For instance, the type may be inferred as {}[] when the runtime result is a single object {}.

Related issues
#546
supabase/supabase#29086

What is the new behavior?

This PR updates the select-query-parser to handle these cases more accurately by:

  • Extending the handling logic for the !left operator, similar to the existing logic for the !inner operator.
  • Returning a single object for relationships when the runtime result is also a single object.

Additional context

The TypeScript code in select-query-parser is quite complex. I would appreciate a thorough review of this fix.
Additional tests have been added to cover both runtime and typing scenarios. This helped uncover more edge cases, some of which still need further solutions.

Known Issues:

Currently, there is no distinction between possibly nullable and non-nullable results for zero-to-one or one-to-one relations. To handle this properly, the PR always returns null as a possible option. However, a more accurate solution would involve enhancements like adding an isOneToOne option in Relationships that marks foreign keys as nullable or non-nullable based on columns[] type definitions.

PS

Also took the chance to fix the CI workflow by replacing the deprecated docker-compose with docker compose command.

@avallete avallete requested a review from soedirgo September 9, 2024 07:20
@soedirgo
Copy link
Member

Thanks! I think this fixes supabase/supabase#29086 but not #546 - will investigate that separately

@soedirgo soedirgo enabled auto-merge (squash) September 10, 2024 17:33
@soedirgo soedirgo merged commit c2049b2 into supabase:master Sep 10, 2024
1 check passed
Copy link

🎉 This PR is included in version 1.16.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants