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

Add note about typescript support for fetching #959

Open
TimurKr opened this issue Jan 24, 2024 · 0 comments
Open

Add note about typescript support for fetching #959

TimurKr opened this issue Jan 24, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@TimurKr
Copy link

TimurKr commented Jan 24, 2024

Improve documentation

In the documentation for fetching, under Query the same referenced table multiple times, it states an approach, which doesn't infer correct types on the resulting object.

Link

https://supabase.com/docs/reference/javascript/select

Describe the problem

The documentation states this approach

const { data, error } = await supabase
  .from('messages')
  .select(`
    content,
    from:sender_id(name),
    to:receiver_id(name)
  `)

This works and fetches the correct data, but with typescript, the types are incorrect; from and to are both typed as {}[].

Describe the improvement

I believe the documentation should mention another possible approach, which is also mentioned in the PostgREST documentation, which returns the correct data and infers the types correctly:

const { data, error } = await supabase
  .from('messages')
  .select(`
      content,
      from:users!messages_from_fkey(name),
      to:users!messages_from_fkey(name)
  `)

Here the users is the name of the foreign table from which we are querying and messages_from_fkey and messages_from_fkey are the names of the foreign key constraints.

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

No branches or pull requests

1 participant