|
1 | 1 | /* eslint-disable */ |
2 | | -import type { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; |
3 | | -import type { FragmentDefinitionNode } from 'graphql'; |
4 | | -import type { Incremental } from './graphql'; |
| 2 | +import type { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core'; |
| 3 | +import type { Incremental, TypedDocumentString } from './graphql'; |
5 | 4 |
|
6 | 5 |
|
7 | 6 | export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration< |
@@ -70,18 +69,15 @@ export function makeFragmentData< |
70 | 69 | return data as FragmentType<F>; |
71 | 70 | } |
72 | 71 | export function isFragmentReady<TQuery, TFrag>( |
73 | | - queryNode: DocumentTypeDecoration<TQuery, any>, |
74 | | - fragmentNode: TypedDocumentNode<TFrag>, |
75 | | - data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined |
| 72 | + queryNode: TypedDocumentString<TQuery, any>, |
| 73 | + fragmentNode: TypedDocumentString<TFrag, any>, |
| 74 | + data: FragmentType<TypedDocumentString<Incremental<TFrag>, any>> | null | undefined |
76 | 75 | ): data is FragmentType<typeof fragmentNode> { |
77 | | - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__ |
78 | | - ?.deferredFields; |
| 76 | + const deferredFields = queryNode.__meta__?.deferredFields as Record<string, (keyof TFrag)[]>; |
| 77 | + const fragName = fragmentNode.__meta__?.fragmentName as string | undefined; |
79 | 78 |
|
80 | | - if (!deferredFields) return true; |
| 79 | + if (!deferredFields || !fragName) return true; |
81 | 80 |
|
82 | | - const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; |
83 | | - const fragName = fragDef?.name?.value; |
84 | | - |
85 | | - const fields = (fragName && deferredFields[fragName]) || []; |
| 81 | + const fields = deferredFields[fragName] ?? []; |
86 | 82 | return fields.length > 0 && fields.every(field => data && field in data); |
87 | 83 | } |
0 commit comments