Skip to content

fix: rpc return type #394

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

Merged
merged 4 commits into from
Feb 6, 2023
Merged

fix: rpc return type #394

merged 4 commits into from
Feb 6, 2023

Conversation

soedirgo
Copy link
Member

@soedirgo soedirgo commented Feb 4, 2023

What kind of change does this PR introduce?

Fixes #387.

RPC return types aren't getting propagated properly. E.g. if a function returns boolean, the data will be typed as boolean[].

To fix this, we change PostgrestBuilder's type parameter to be the actual type of data, instead of the element type of data (which assumes data is always an array, which is incorrect).

In doing so we effectively remove all usage of PostgrestResponse and PostgrestMaybeSingleResponse. We can stop exporting these on the next major version.

This also fixes the behavior of .returns<NewResult>(), which was inconsistent with the documentation (i.e. data was typed as NewResult[] instead of NewResult).

RPC return types aren't getting propagated properly. E.g. if a function
returns `boolean`, the `data` will be typed as `boolean[]`.

To fix this, we change PostgrestBuilder's type parameter to be the
actual type of `data`, instead of the element type of `data` (which
assumes `data` is always an array, which is incorrect).

In doing so we effectively remove all usage of `PostgrestResponse` and
`PostgrestMaybeSingleResponse`. We can stop exporting these on the next
major version.

This also fixes the behavior of `.returns<NewResult>()`, which was
inconsistent with the documentation (i.e. `data` was typed as
`NewResult[]` instead of `NewResult`).
@soedirgo soedirgo merged commit f8edc51 into master Feb 6, 2023
@soedirgo soedirgo deleted the fix/rpc-return-type branch February 6, 2023 03:31
@github-actions
Copy link

github-actions bot commented Feb 6, 2023

🎉 This PR is included in version 1.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@natedunn
Copy link

natedunn commented Feb 9, 2023

oof, i was wondering why all my types got borked overnight.

@soedirgo
Copy link
Member Author

Sorry about that @natedunn - do you mind sharing how it's breaking your types? While we consider it a bug here we do want to make sure the fix isn't causing more issues at least.

@natedunn
Copy link

@soedirgo Yeah I can understand the mentality there, so no worries.

There's not much to describe in terms of my issues. The PR description laid it out pretty well, so I knew what I had to change:

This stopped working

  .returns<SomeDefinedType>()

And this fixed the issue

  .returns<SomeDefinedType[]>()

soedirgo referenced this pull request in supabase/cli May 30, 2023
@bombillazo
Copy link

bombillazo commented May 30, 2023

I created this issue: #430

It is probably related to this.

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.

rcp() return type does not match SQL function return type
5 participants