Skip to content

Commit 7fc5fcb

Browse files
authored
fix: detect !inner in one-to-one relationships (#530)
1 parent dc42087 commit 7fc5fcb

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/select-query-parser.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ type ConstructFieldDefinition<
228228
? R
229229
: unknown
230230
> extends true
231-
? Child | null
231+
? Field extends { inner: true }
232+
? Child
233+
: Child | null
232234
: Relationships extends unknown[]
233235
? HasFKey<Field['hint'], Relationships> extends true
234236
? Field extends { inner: true }
@@ -259,7 +261,9 @@ type ConstructFieldDefinition<
259261
? R
260262
: unknown
261263
> extends true
262-
? Child | null
264+
? Field extends { inner: true }
265+
? Child
266+
: Child | null
263267
: Relationships extends unknown[]
264268
? HasFKeyToFRel<Field['original'], Relationships> extends true
265269
? Field extends { inner: true }

test/index.test-d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,18 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
154154
{
155155
const { data: message, error } = await postgrest
156156
.from('messages')
157-
.select('user:users!inner(*)')
157+
.select('channels!inner(*, channel_details!inner(*))')
158158
.single()
159159
if (error) {
160160
throw new Error(error.message)
161161
}
162-
expectType<Database['public']['Tables']['users']['Row']>(message.user)
162+
type ExpectedType = Prettify<
163+
Database['public']['Tables']['channels']['Row'] & {
164+
channel_details: Database['public']['Tables']['channel_details']['Row']
165+
}
166+
>
167+
168+
expectType<ExpectedType>(message.channels)
163169
}
164170

165171
// one-to-many relationship

0 commit comments

Comments
 (0)