Skip to content

Commit

Permalink
detect !inner in one-to-one relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
wyozi committed Apr 3, 2024
1 parent 7c3dd21 commit 63271ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/select-query-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ type ConstructFieldDefinition<
? R
: unknown
> extends true
? Child | null
? Field extends { inner: true }
? Child
: Child | null
: Relationships extends unknown[]
? HasFKey<Field['hint'], Relationships> extends true
? Field extends { inner: true }
Expand Down Expand Up @@ -259,7 +261,9 @@ type ConstructFieldDefinition<
? R
: unknown
> extends true
? Child | null
? Field extends { inner: true }
? Child
: Child | null
: Relationships extends unknown[]
? HasFKeyToFRel<Field['original'], Relationships> extends true
? Field extends { inner: true }
Expand Down
10 changes: 8 additions & 2 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,18 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
{
const { data: message, error } = await postgrest
.from('messages')
.select('user:users!inner(*)')
.select('channels!inner(*, channel_details!inner(*))')
.single()
if (error) {
throw new Error(error.message)
}
expectType<Database['public']['Tables']['users']['Row']>(message.user)
type ExpectedType = Prettify<
Database['public']['Tables']['channels']['Row'] & {
channel_details: Database['public']['Tables']['channel_details']['Row']
}
>

expectType<ExpectedType>(message.channels)
}

// one-to-many relationship
Expand Down

0 comments on commit 63271ca

Please sign in to comment.