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

ParserError on return type with aggregate functions #1000

Open
2 tasks done
DuncanLHS opened this issue Mar 28, 2024 · 1 comment
Open
2 tasks done

ParserError on return type with aggregate functions #1000

DuncanLHS opened this issue Mar 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

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

There appears to be a problem with the return TS types when using aggregate functions and referenced tables. Instead of getting the expected return type, I'm getting ParserError<'error'>

Example with my function (I believe this is correct and it does run successfully):

export async function getAllProjectsSummary(request: Request) {
  const { supabase } = createSupabaseServerClient({ request });
  const { data, error } = await supabase.from("projects").select(
    "project_no, project_name, project_media(count()), documents(count())",
  );
  if (error) {
    return { error: error.message };
  }
  return data;
}

The data return type here is ParserError<"Expected identifier at `)), documents(count())`">[]

To Reproduce

  1. Create 2 tables with a one-to-many relationship between the first and second.
  2. Run a select postgREST query on table 1 including including an aggregate function on related columns in table 2

Expected behavior

Expected data return type to reflect the query.

i.e.

data: {
    project_no: string;
    project_name: string;
    project_media: {
        count: {}[];
    }[];
    documents: {
        count: {}[];
    }[];
}[]

System information

  • supabase-js: 2.41.1

Additional context

Interestingly using count(*) or count('*') generates the correct return type so it would appear the query builder just isn't handling the brackets correctly for aggregate functions and is expecting something between them as it would for referenced tables. These of course generate an error as they're incorrect syntax for the count function.

A very quick check on a simpler query seems to yield the same error even without referencing related tables.

@DuncanLHS DuncanLHS added the bug Something isn't working label Mar 28, 2024
@DuncanLHS
Copy link
Author

DuncanLHS commented Mar 28, 2024

Appears to have been fixed in postgrest-js v1.13. Dependency needs updating here.

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

1 participant