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

After upgrading supabase-js Typescript fails with SelectQueryError #568

Open
2 tasks done
kussberg opened this issue Oct 29, 2024 · 6 comments
Open
2 tasks done

After upgrading supabase-js Typescript fails with SelectQueryError #568

kussberg opened this issue Oct 29, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@kussberg
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

I have updated the supabase-js in my React Native project and suddenly code that worked before with Typescript, now gives an error.

To Reproduce

Following code:

const {data: userData, error} = await supabase
          .from('users')
          .select('*')
          .eq('id', userId)
          .single();

Now gives an error with Typescript:

Argument of type 'SelectQueryError<"Invalid Relationships cannot infer result type">' is not assignable to parameter of type 'SetStateAction<UserRowData | null>'.ts(2345)

System information

  • OS: macOS, VSCode
  • Browser (if applies): React Native
  • Version of supabase-js: v2.46.0
  • Version of Node.js: v20.18.0
@kussberg kussberg added the bug Something isn't working label Oct 29, 2024
@avallete
Copy link
Member

Thanks for reporting this! To help us reproduce the issue, could you provide the type definitions for your database used by the client ? If the information is sensitive, you can send it via a Supabase support ticket. With the select query you already included in the issue that should be enough to identify and reproduce the issue.

@maximilian-hammerl
Copy link

We have the same problem with a few of our queries. For example:

async function selectUserIdByEmailAddress(emailAddress: string): Promise<string> {
  const { data, error } = await supabaseAdmin
    .from('user_profile')
    .select('user_id')
    .eq('email_address', emailAddress)
    .single()

  if (error) {
    throw new Error(error.message)
  }

  return data.user_id
}

(simplified)

The error message here is:

Property 'user_id' does not exist on type 'SelectQueryError<"Invalid Relationships cannot infer result type">'.

Is this part of the Database type enough to help you fix this error?

export type Database = {
  public: {
    Tables: {
      user_profile: {
        Row: {
          created_at: string | null
          email_address: string | null
          first_name: string | null
          language_code: Database["public"]["Enums"]["language_code"]
          last_name: string | null
          user_id: string
        }
        Insert: {
          created_at?: string | null
          email_address?: string | null
          first_name?: string | null
          language_code?: Database["public"]["Enums"]["language_code"]
          last_name?: string | null
          user_id: string
        }
        Update: {
          created_at?: string | null
          email_address?: string | null
          first_name?: string | null
          language_code?: Database["public"]["Enums"]["language_code"]
          last_name?: string | null
          user_id?: string
        }
        Relationships: []
      }
      ...
    }
    Views: {
      ...
    }
    Functions: {
      ...
    }
    Enums: {
      language_code: "en" | "de"
      ...
    }
    CompositeTypes: {
      ...
    }
  }
}

@f0n2
Copy link

f0n2 commented Oct 30, 2024

I am having the same issue with that error since updating. It broke all my site's data fetching/filling. Reverting to the previous version fixed the problem.

@avallete
Copy link
Member

Hey @f0n2,

Apologies for the issue. We've reverted the change for now while we gather more debugging data to identify what’s causing the problem on specific projects but not in our tests or on other projects.

@maximilian-hammerl

Thanks for sharing the type subset. Unfortunately, I couldn’t reproduce the issue with it alone. The type inference logic is highly recursive, so the root of the issue might lie elsewhere in your setup.

If your project is hosted on Supabase, it would be great if you could open a support ticket: https://supabase.com/dashboard/support/new. Please check the "Allow Supabase Support to access your project temporarily" box. This will allow us to access your database types directly and investigate further.

@maximilian-hammerl
Copy link

maximilian-hammerl commented Oct 30, 2024

@avallete, we created a support ticket. The ID is: 15847753261
You should be able to access our project

@avallete
Copy link
Member

avallete commented Nov 6, 2024

Hey @kussberg @f0n2

We just released supabase-js version 2.46.2-rc.1. Could you give it a try and let us know if it resolves the regressions you encountered with 2.46.0? Your feedback would be super helpful!

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

4 participants