Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
feat: optional field reference
Browse files Browse the repository at this point in the history
  • Loading branch information
ishowta committed Feb 14, 2022
1 parent a4c32f3 commit ce77af5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export type JoinedDataInner<
[K in Exclude<
keyof GraphQueryQueryType<T, Q>,
keyof T
>]: GraphQueryQueryType<T, Q>[K] extends [infer Ref, infer UQuery]
>]: GraphQueryQueryType<T, Q>[K] extends
| [infer Ref, infer UQuery]
| undefined
? Ref extends AnyReference
? UQuery extends Function
? UQuery extends GraphQuery<RefToDoc<Ref>>
Expand Down
8 changes: 4 additions & 4 deletions src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export function useQuery<
}

export function field<
Ref extends AnyReference,
Q extends GraphQuery<RefToDoc<Ref>>
>(ref: Ref, query: Q): [Ref, Q] {
return [ref, query];
Ref extends AnyReference | undefined,
Q extends GraphQuery<RefToDoc<NonNullable<Ref>>>
>(ref: Ref, query: Q): undefined extends Ref ? [Ref, Q] | undefined : [Ref, Q] {
return ref ? [ref, query] : (undefined as any);
}

0 comments on commit ce77af5

Please sign in to comment.