-
-
Notifications
You must be signed in to change notification settings - Fork 332
Embedded resource types ignore !inner
/ is not null
#943
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
Comments
I believe this issue significantly impacts the usability of type inference for queries that involve nested resources, particularly in scenarios where the nested resource's presence is essential for the integrity of the returned data. To elaborate, even when a database schema explicitly defines a foreign key (e.g., country_id) as NOT NULL, the type of Query1Type.countries could still be nullable. This situation arises not from the database schema itself but from the potential limitations of the client's permissions making the query. Therefore, unless the framework acknowledges the client's permissions level—specifically, whether it operates with sufficient privileges (such as a service role client)—or allows field-specific permissions overrides, marking countries as nullable remains technically correct. However, the !inner and is not null constructs currently serve as mechanisms to enforce non-nullability constraints on a per-field basis, implicitly handling permission constraints by excluding parent objects lacking sufficient permissions. This approach, while functional, could lead to verbose query syntax due to the frequent need to specify !inner, especially in complex queries where non-nullability is a common requirement. One potential improvement could be introducing a mechanism to set !inner as the default behavior for certain queries or within the context of specific clients or roles. This change would streamline query construction without sacrificing the flexibility or security model provided by the current permission system. Considering that !inner aligns with the typical default behavior for Postgres queries, adopting it as a default in our context seems logical. However, this approach might diverge due to choices made in the PostgREST library, which might not set !inner as the default. While I am not fully aware of all the implications such a default behavior might entail, especially when exceptions are necessary for specific fields, I believe it is an idea worth exploring for its potential to simplify query syntax and enhance overall usability. |
Facing this on my end as well. Seems like a regression though. This issue was supposedly fixed last august supabase/postgrest-js#456 |
Hey everyone ! We've reworked the result inference in To test it out, update your npm install supabase-js@2.46.0-rc.1 Please let us know if you encounter any issues, especially with retro-compatibility, so we can finalize it for the next release. |
@avallete - It solved one issue I was having with the type inference but it created another one that I didn't have in Solved Issue:
New Issue:
![]() ![]() Let me know if you need any additional info to debug :) GL! |
Hey @IPJT ! Thanks for the feedback, a few questions to help with debugging this out:
Also I would not expect you to get those Meanwhile if you do something like:
Do you get a more useful infos in the value type ? |
Hi @avallete - Thanks for your reply
Yeah, I removed the types and regenerated them after upgrading to the latest cli version. Didn't help though.
Would it be possible for me to just give you access to our Supabase project where the full schema is deployed? Nothing secret in there :P
The inferred type for ![]() As seen by the logs in the image the runtime behaviour is as expected, it does indeed find the relation. Would be happy to get on a call with you if that would in any way help you debug this. |
Hey @IPJT ! Thank's for all those additional details.
Yes that would be the best way to debug this I think. If that's okay for you we have a procedure for this, you need to fill up a support ticket (here: https://supabase.com/dashboard/support/new) And tick the |
Thank's to you, this should now be fixed ! Thanks for reporting and providing all details for debugging 👍 |
The fix has been released in |
Works like a charm. Thanks bud! @avallete |
Bug report
Describe the bug
When performing a many-to-one join in supabase using either
!inner
or.not('reference', 'is', null)
, the returned type isT | null
but should beT
.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Taking the example tables:
and then create a number of queries against supabase-js using Typescript:
Expected behavior
Resulting typescript types should be:
In all cases, where I have labeled "This should absolutely not be nullable", supabase-js returns a nullable type
Screenshots
If applicable, add screenshots to help explain your problem.
System information
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: