supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
967 stars 130 forks source link

Database types on NX Monorepo #360

Closed digoburigo closed 1 year ago

digoburigo commented 1 year ago

Bug report

Describe the bug

I'm trying to get the types of the database on postgrest client in a Nx monorepo and it's not working properly. I don't know if this is a NX problem or postgrest-js. Can someone help with this?

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to this repo
  2. Clone it
  3. Install packages with npm install
  4. Check the postgrest client on the file apps/pgrest/pages/index.tsx
  5. You will find that the client it's not doing the auto completion

Expected behavior

Autocomplete based on the Database type

Screenshots

image

System information

soedirgo commented 1 year ago

Are you writing the types manually? Some of the fields are mandatory even though you have none of them. An empty schema looks like:

export type Json =
  | string
  | number
  | boolean
  | null
  | { [key: string]: Json }
  | Json[]

export interface Database {
  public: {
    Tables: {
      [_ in never]: never
    }
    Views: {
      [_ in never]: never
    }
    Functions: {
      [_ in never]: never
    }
    Enums: {
      [_ in never]: never
    }
  }
}
digoburigo commented 1 year ago

Oh ok, to make the types work properly I must use the supabase cli to generate the database types? I will try that to see. Thanks for the tip

digoburigo commented 1 year ago

Yeah, now I'm getting the autocompletion, but for some reason in the method select it's only showing the * to get all the fields, is there something more to configure? I pushed to the repo the change with the correct database type.

soedirgo commented 1 year ago

Hmm I don't think autocomplete is supposed to work in .select(), but it should work for filters.

digoburigo commented 1 year ago

Oh ok, so the select method don't have the autocompletion because of the vairous features provided by PosgREST? Thanks, Really apreciated the help! Feel free to close the issue

soedirgo commented 1 year ago

:+1: it's more to do with how the typings are implemented rather than what features PostgREST has