supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
1.03k stars 133 forks source link

Using different schema for Supabase prevents build, results in error #478

Open damywise opened 1 year ago

damywise commented 1 year ago

Bug report

Describe the bug

Heya, I'm having trouble trying to use different table schema using Supabase for the template refine project

// utility/supabaseClient.ts
export const supabaseClient = createClient(SUPABASE_URL, SUPABASE_KEY, {
    db: {
// problematic part vv
        schema: "custom",
    },
    auth: {
        persistSession: true,
    },
});

That exact code results in the following error.


22:08:57.278    Executing user command: npm run build
22:08:57.892    
22:08:57.892    > data-provider-supabase@3.25.0 build
22:08:57.892    > tsc && refine build
22:08:57.892    
22:09:02.920    src/App.tsx(328,48): error TS2345: Argument of type 'SupabaseClient<any, "custom", any>' is not assignable to parameter of type 'SupabaseClient<any, "public", any>'.
22:09:02.921      Type '"custom"' is not assignable to type '"public"'.
22:09:02.921    src/App.tsx(329,48): error TS2345: Argument of type 'SupabaseClient<any, "custom", any>' is not assignable to parameter of type 'SupabaseClient<any, "public", any>'.
22:09:02.967    Failed: build command exited with code: 2
22:09:03.827    Failed: error occurred while running build command

To Reproduce

  1. Get the Supabase refine template
  2. Change supabaseClient options schema from "public" to anything else
  3. npm run build
  4. Error

Expected behavior

Works

Screenshots

If applicable, add screenshots to help explain your problem.

System information

Additional context

Type '"product"' is not assignable to type '"public"'.ts(2322)
---
(property) schema?: ("public" extends keyof Database ? "public" : string & keyof Database) | undefined

Also npm start works but npm run build doesn't

garygcchiu commented 10 months ago

Running into the same problem. It's a blocker for running Edge Function tests as well if I need to create a client and use data in a non-public schema.

error: TS2322 [ERROR]: Type 'SupabaseClient<any, string, any>' is not assignable to type 'SupabaseClient<any, "public", any>'.
  Type 'string' is not assignable to type '"public"'.
    var client: SupabaseClient = createClient(supabaseUrl, supabaseKey, options) // options has db: { schema: 'my-schema' }
        ~~~~~~
gerynugrh commented 6 months ago

A way to solve this would be to write it like this:

  const supabase = createClient<Omit<Database, "public">>(
    config.SUPABASE_URL,
    config.SUPABASE_SERVICE_ROLE_KEY,
    {
      db: {
        schema: "custom",
      },
    }
  );

It seems that the typing only allow public if public is a key of Database. Otherwise, it would allow the schema to be all possible keys of Database. Hence, the removal of the key public above.