supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.

Home Page:https://supabase.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Latest update produces an inferred type error on select statements with a table join

Aerilym opened this issue · comments

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

An error with Typescript type interpretation with supabase-js select query with table join.
This error occurred when updating from 2.26.0 to 2.29.0. (But I think it was the dependencies updating that broke it, i just changed the supabase version from ^2.26.0 to ^2.29.0.

To Reproduce

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

  1. Use Supabase-js with TypeScript.
  2. Generate supabase types. See https://supabase.com/docs/reference/javascript/typescript-support
  3. Make a select query with a table join.
  const { data, error } = await supabase
    .from('show_members')
    .select(
      `role_flag, show_id 
      (
      team_id
      )`
    )
    .eq('user_id', userId)
    .eq('show_id', showId)
    .maybeSingle();
  1. Observe the returned data has an issue in the type interpretation of the joined column
    Inferred Type:
const data: {
    role_flag: string;
    show_id: SelectQueryError<"Referencing missing column `team_id`">[];
} | null

Second example inferred type:

const shows: {
    id: string;
    created_at: string;
    title: string;
    team_id: SelectQueryError<"Referencing missing column `description`">[];
}[] | null

Expected behavior

No type error to occur
Expected Inferred Type:

const data: {
    role_flag: string;
    show_id: {
        team_id: unknown
    }[];
} | null

Second example expected inferred type:

const shows: {
    id: string;
    created_at: string;
    title: string;
    team_id: {
        description: unknown
        }[];
}[] | null

This error occurred when updating from 2.26.0 to 2.29.0

System information

  • OS: Ubuntu 22.04.2 LTS
  • Version of supabase-js: 2.29.0
  • Version of Node.js: 16.7.1

I had some issues getting it back to how it was working before with all the version changes, but here is the supabase-js section of my yarn.lock. This configuration works:

"@supabase/supabase-js@^2.26.0":
  version "2.29.0"
  resolved "https://registry.yarnpkg.com/@supabase/supabase-js/-/supabase-js-2.29.0.tgz#7bc9983188d01f37cf53e2afcf1a1ad14a772129"
  integrity sha512-Lb/7sxsTLAzYl6Op1CL+hH+9NC3FUAj1FfgUUbCBysJlAF39/kbdrimq/JMFOAnN1/cqpkR3rR/1WmU9ARS29g==
  dependencies:
    "@supabase/functions-js" "^2.1.0"
    "@supabase/gotrue-js" "2.43.1"
    "@supabase/postgrest-js" "^1.7.0"
    "@supabase/realtime-js" "^2.7.3"
    "@supabase/storage-js" "^2.5.1"
    cross-fetch "^3.1.5"
    
"@supabase/functions-js@^2.1.0":
  version "2.1.1"
  resolved "https://registry.yarnpkg.com/@supabase/functions-js/-/functions-js-2.1.1.tgz#31eb64734d59e6da84927e6f50f627ad5e03c519"
  integrity sha512-bIR1Puae6W+1/MzPfYBWOG/SCWGo4B5CB7c0ZZksvliNEAzhxNBJ0UFKYINcGdGtxG8ZC+1xr3utWpNZNwnoRw==
  dependencies:
    cross-fetch "^3.1.5"

"@supabase/gotrue-js@2.43.1":
  version "2.43.1"
  resolved "https://registry.yarnpkg.com/@supabase/gotrue-js/-/gotrue-js-2.43.1.tgz#4623791433f0b7ef4c17f0d880fba1f0307b4c81"
  integrity sha512-HVjjElEPbM5sDoK1pXry/H181X7A1a9G9O68PZwN276y/EUwWOw3pA8KKKSRTaTSiK+41BPC8HUfsfbe7470RQ==
  dependencies:
    cross-fetch "^3.1.5"

"@supabase/postgrest-js@^1.7.0":
  version "1.7.0"
  resolved "https://registry.yarnpkg.com/@supabase/postgrest-js/-/postgrest-js-1.7.0.tgz#69ffb605d083d4761d9c30075c04b10e32cc7fd0"
  integrity sha512-wLADHZ5jm7LljF4GigK0H2vc1wGupBY2hGYfb4fVo0UuyMftmA6tOYy+ZpMH/vPq01CUFwXGwvIke6kyqh/QDg==
  dependencies:
    cross-fetch "^3.1.5"

"@supabase/realtime-js@^2.7.3":
  version "2.7.3"
  resolved "https://registry.yarnpkg.com/@supabase/realtime-js/-/realtime-js-2.7.3.tgz#cbcb84181add681ab99c87032bfe88101c6863b3"
  integrity sha512-c7TzL81sx2kqyxsxcDduJcHL9KJdCOoKimGP6lQSqiZKX42ATlBZpWbyy9KFGFBjAP4nyopMf5JhPi2ZH9jyNw==
  dependencies:
    "@types/phoenix" "^1.5.4"
    "@types/websocket" "^1.0.3"
    websocket "^1.0.34"

"@supabase/storage-js@^2.5.1":
  version "2.5.1"
  resolved "https://registry.yarnpkg.com/@supabase/storage-js/-/storage-js-2.5.1.tgz#16c4c088996e0395034717836e626f14df63a349"
  integrity sha512-nkR0fQA9ScAtIKA3vNoPEqbZv1k5B5HVRYEvRWdlP6mUpFphM9TwPL2jZ/ztNGMTG5xT6SrHr+H7Ykz8qzbhjw==
  dependencies:
    cross-fetch "^3.1.5"

Here is a diff of the two yarn.lock files, the original (which works) has had supabase-js incrementally updated, the new one has been freshly rebuilt (removed links):

"@supabase/functions-js@^2.1.0":
-  version "2.1.1"
+ version "2.1.2"
  dependencies:
    cross-fetch "^3.1.5"

"@supabase/gotrue-js@2.43.1":
  version "2.43.1"
  resolved "https://registry.yarnpkg.com/@supabase/gotrue-js/-/gotrue-js-2.43.1.tgz#4623791433f0b7ef4c17f0d880fba1f0307b4c81"
  integrity sha512-HVjjElEPbM5sDoK1pXry/H181X7A1a9G9O68PZwN276y/EUwWOw3pA8KKKSRTaTSiK+41BPC8HUfsfbe7470RQ==
  dependencies:
    cross-fetch "^3.1.5"

"@supabase/postgrest-js@^1.7.0":
-  version "1.7.0"
+  version "1.7.2"
  resolved "https://registry.yarnpkg.com/@supabase/postgrest-js/-/postgrest-js-1.7.0.tgz#69ffb605d083d4761d9c30075c04b10e32cc7fd0"
  integrity sha512-wLADHZ5jm7LljF4GigK0H2vc1wGupBY2hGYfb4fVo0UuyMftmA6tOYy+ZpMH/vPq01CUFwXGwvIke6kyqh/QDg==
  dependencies:
    cross-fetch "^3.1.5"

"@supabase/realtime-js@^2.7.3":
  version "2.7.3"
  dependencies:
    "@types/phoenix" "^1.5.4"
    "@types/websocket" "^1.0.3"
    websocket "^1.0.34"

"@supabase/storage-js@^2.5.1":
  version "2.5.1"
  dependencies:
    cross-fetch "^3.1.5"

"@supabase/supabase-js@^2.26.0":
  version "2.29.0"
  dependencies:
    "@supabase/functions-js" "^2.1.0"
    "@supabase/gotrue-js" "2.43.1"
    "@supabase/postgrest-js" "^1.7.0"
    "@supabase/realtime-js" "^2.7.3"
    "@supabase/storage-js" "^2.5.1"
    cross-fetch "^3.1.5"

This seems to be the offending commit: aeb2ce9
I used to get type unknown on joins, but now with this error type, I can't use joins on the newer versions. Have I been using joins incorrectly or is this an issue with the type generation?