Skip to content

Commit

Permalink
types: Single key result with __typename still counts as single key (#…
Browse files Browse the repository at this point in the history
…1163)

Previously, a response with a single key and a __typename field would
not be considered as having a single key and could not be
automatically extracted by useQuery.
  • Loading branch information
canac committed Jul 4, 2021
1 parent c877bb8 commit 619b0d1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export type IsUnion<T, U = T> = U extends any ? ([T] extends [U] ? false : true)
/**
* Extracts an inner type if T has a single key K, otherwise it returns T.
*/
export type ExtractSingleKey<T, K extends keyof T = keyof T> = IsUnion<K> extends true ? T : T[K]
export type ExtractSingleKey<T, K extends keyof T = keyof T, KWithoutTypename extends K = Exclude<K, '__typename'>> = IsUnion<KWithoutTypename> extends true ? T : T[KWithoutTypename]
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ export interface ExampleUpdatedSubscriptionVariables {
}

export interface SingleKeyExampleQuery {
__typename?: 'Root'
example?: {
__typename?: 'Example'
}
}

export interface MultiKeyExampleQuery {
__typename?: 'Root'
example?: {
__typename?: 'Example'
}
Expand Down

0 comments on commit 619b0d1

Please sign in to comment.