Skip to content

ParserError on return type with aggregate functions #1000

@DuncanLHS

Description

@DuncanLHS

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions