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 c845bd8
Show file tree
Hide file tree
Showing 2 changed files with 11 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
7 changes: 5 additions & 2 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,15 @@ 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)
expectType<Database['public']['Tables']['channels']['Row']>(message.channels)
expectType<Database['public']['Tables']['channel_details']['Row']>(
message.channels.channel_details
)
}

// one-to-many relationship
Expand Down

0 comments on commit c845bd8

Please sign in to comment.