Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit eee4612

Browse files
committed
fix(rpc): select chained with filter
Related: supabase/supabase-js#1365
1 parent d14e642 commit eee4612

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/PostgrestTransformBuilder.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import PostgrestBuilder from './PostgrestBuilder'
2+
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
23
import { GetResult } from './select-query-parser/result'
34
import { GenericSchema, CheckMatchingArrayTypes } from './types'
45

@@ -23,7 +24,7 @@ export default class PostgrestTransformBuilder<
2324
NewResultOne = GetResult<Schema, Row, RelationName, Relationships, Query>
2425
>(
2526
columns?: Query
26-
): PostgrestTransformBuilder<Schema, Row, NewResultOne[], RelationName, Relationships> {
27+
): PostgrestFilterBuilder<Schema, Row, NewResultOne[], RelationName, Relationships> {
2728
// Remove whitespaces except when quoted
2829
let quoted = false
2930
const cleanedColumns = (columns ?? '*')
@@ -43,7 +44,7 @@ export default class PostgrestTransformBuilder<
4344
this.headers['Prefer'] += ','
4445
}
4546
this.headers['Prefer'] += 'return=representation'
46-
return this as unknown as PostgrestTransformBuilder<
47+
return this as unknown as PostgrestFilterBuilder<
4748
Schema,
4849
Row,
4950
NewResultOne[],

test/embeded_functions_join.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -961,21 +961,37 @@ describe('rpc', () => {
961961
`)
962962
})
963963

964-
test('function with row input with followup select', async () => {
965-
const res = await rpcQueries['function with row input with followup select']
964+
test('should be able to filter before and after select rpc', async () => {
965+
const res = await postgrest
966+
.rpc('get_user_profile', {
967+
//@ts-expect-error will complain about missing the rest of the params
968+
user_row: { username: 'supabot' },
969+
})
970+
.select('id, username, users(username, catchphrase)')
971+
.eq('username', 'nope')
972+
966973
expect(res).toMatchInlineSnapshot(`
967974
Object {
968975
"count": null,
969-
"data": Array [
970-
Object {
971-
"id": 1,
972-
"username": "supabot",
973-
"users": Object {
974-
"catchphrase": "'cat' 'fat'",
975-
"username": "supabot",
976-
},
977-
},
978-
],
976+
"data": Array [],
977+
"error": null,
978+
"status": 200,
979+
"statusText": "OK",
980+
}
981+
`)
982+
const res2 = await postgrest
983+
.rpc('get_user_profile', {
984+
//@ts-expect-error will complain about missing the rest of the params
985+
user_row: { username: 'supabot' },
986+
})
987+
// should also be able to fitler before the select
988+
.eq('username', 'nope')
989+
.select('id, username, users(username, catchphrase)')
990+
991+
expect(res2).toMatchInlineSnapshot(`
992+
Object {
993+
"count": null,
994+
"data": Array [],
979995
"error": null,
980996
"status": 200,
981997
"statusText": "OK",

0 commit comments

Comments
 (0)