|
1 | | -import { ResultOf, TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; |
| 1 | +import { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core'; |
2 | 2 |
|
3 | | -export type FragmentType<TDocumentType extends DocumentNode<any, any>> = TDocumentType extends DocumentNode< |
4 | | - infer TType, |
5 | | - any |
6 | | -> |
7 | | - ? TType extends { ' $fragmentName'?: infer TKey } |
8 | | - ? TKey extends string |
9 | | - ? { ' $fragmentRefs'?: { [key in TKey]: TType } } |
| 3 | +export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = |
| 4 | + TDocumentType extends DocumentTypeDecoration<infer TType, any> |
| 5 | + ? TType extends { ' $fragmentName'?: infer TKey } |
| 6 | + ? TKey extends string |
| 7 | + ? { ' $fragmentRefs'?: { [key in TKey]: TType } } |
| 8 | + : never |
10 | 9 | : never |
11 | | - : never |
12 | | - : never; |
| 10 | + : never; |
13 | 11 |
|
14 | 12 | // return non-nullable if `fragmentType` is non-nullable |
15 | 13 | export function useFragment<TType>( |
16 | | - _documentNode: DocumentNode<TType, any>, |
17 | | - fragmentType: FragmentType<DocumentNode<TType, any>> |
| 14 | + _documentNode: DocumentTypeDecoration<TType, any>, |
| 15 | + fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> |
18 | 16 | ): TType; |
19 | 17 | // return nullable if `fragmentType` is nullable |
20 | 18 | export function useFragment<TType>( |
21 | | - _documentNode: DocumentNode<TType, any>, |
22 | | - fragmentType: FragmentType<DocumentNode<TType, any>> | null | undefined |
| 19 | + _documentNode: DocumentTypeDecoration<TType, any>, |
| 20 | + fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined |
23 | 21 | ): TType | null | undefined; |
24 | 22 | // return array of non-nullable if `fragmentType` is array of non-nullable |
25 | 23 | export function useFragment<TType>( |
26 | | - _documentNode: DocumentNode<TType, any>, |
27 | | - fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>> |
| 24 | + _documentNode: DocumentTypeDecoration<TType, any>, |
| 25 | + fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> |
28 | 26 | ): ReadonlyArray<TType>; |
29 | 27 | // return array of nullable if `fragmentType` is array of nullable |
30 | 28 | export function useFragment<TType>( |
31 | | - _documentNode: DocumentNode<TType, any>, |
32 | | - fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined |
| 29 | + _documentNode: DocumentTypeDecoration<TType, any>, |
| 30 | + fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined |
33 | 31 | ): ReadonlyArray<TType> | null | undefined; |
34 | 32 | export function useFragment<TType>( |
35 | | - _documentNode: DocumentNode<TType, any>, |
| 33 | + _documentNode: DocumentTypeDecoration<TType, any>, |
36 | 34 | fragmentType: |
37 | | - | FragmentType<DocumentNode<TType, any>> |
38 | | - | ReadonlyArray<FragmentType<DocumentNode<TType, any>>> |
| 35 | + | FragmentType<DocumentTypeDecoration<TType, any>> |
| 36 | + | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> |
39 | 37 | | null |
40 | 38 | | undefined |
41 | 39 | ): TType | ReadonlyArray<TType> | null | undefined { |
42 | 40 | return fragmentType as any; |
43 | 41 | } |
44 | 42 |
|
45 | | -export function makeFragmentData<F extends DocumentNode, FT extends ResultOf<F>>( |
| 43 | +export function makeFragmentData<F extends DocumentTypeDecoration<any, any>, FT extends ResultOf<F>>( |
46 | 44 | data: FT, |
47 | 45 | _fragment: F |
48 | 46 | ): FragmentType<F> { |
|
0 commit comments