supabase / postgrest-js

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

Typing ParserError when selecting JSONB field with double quotes #413

Closed kevcodez closed 1 year ago

kevcodez commented 1 year ago

Bug report

Describe the bug

When selecting a JSONB field using jsonb_column->"field_name", the type cannot be determined. Whereas using jsonb_column->field_name works.

To Reproduce

authReadOnly
        .from('projects')
        .select(
          `
          id,
          infrastructure_config->"region"
        `
        )

Property 'region' does not exist on type 'ParserError<"Unexpected input: ->\"region\"">'.

Expected behavior

The type should be parsed correctly, even when using double quotes.

steve-chavez commented 1 year ago

This should be purely a postgrest-js issue. postgREST does allow quoting when using the arrow operators:

curl 'localhost:3000/complex_items?select=settings->foo->"bar"'

[{"bar":"baz"},
 {"bar":"baz"},
 {"bar":"baz"}]
kevcodez commented 1 year ago

@steve-chavez +1 - the code executes just fine, it's only the types that are off 👌

tvogel commented 1 year ago

I think, this also got fixed by https://github.com/supabase/postgrest-js/commit/c69ef50e633e5bf96da8856d769b9f9a11b0e34d .

kevcodez commented 1 year ago

Yup, looking good @tvogel 🥳