Skip to content

Commit f2624f3

Browse files
committed
docs(core): update useFragment JSDoc with refined examples and improved type definitions
1 parent c9b54ed commit f2624f3

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

packages/core/src/composables/useFragment.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ export type UseFragmentResult<TData>
112112
* @returns Object containing fragment state and control methods
113113
*
114114
* @example
115-
* Basic usage:
116115
* ```ts
117116
* const { data, complete } = useFragment({
118117
* fragment: gql`fragment UserFields on User { id name email }`,
@@ -123,8 +122,8 @@ export type UseFragmentResult<TData>
123122
* console.log(data.value?.name)
124123
* ```
125124
*
125+
* // Type-safe access with result (recommended):
126126
* @example
127-
* Type-safe access with result (recommended):
128127
* ```ts
129128
* const { result } = useFragment({
130129
* fragment: USER_FRAGMENT,
@@ -363,14 +362,17 @@ export function useFragment<TData = unknown, TVariables extends OperationVariabl
363362
* Create a helper for complete data access:
364363
* ```ts
365364
* // composables/useCompleteFragment.ts
366-
* export function useCompleteFragment(options) {
367-
* const fragment = useFragment(options)
368-
* const fullData = computed(() =>
369-
* fragment.result.value?.complete
370-
* ? fragment.result.value.data
371-
* : undefined
372-
* )
373-
* return { ...fragment, fullData }
365+
* import type { OperationVariables } from '@apollo/client'
366+
* import type { UseFragmentOptions } from '@vue3-apollo/core'
367+
*
368+
* export function useCompleteFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: UseFragmentOptions<TData, TVariables>) {
369+
* const fragment = useFragment(options)
370+
* const fullData = computed(() =>
371+
* fragment.result.value?.complete
372+
* ? fragment.result.value.data
373+
* : undefined
374+
* )
375+
* return { ...fragment, fullData }
374376
* }
375377
*
376378
* // Usage

0 commit comments

Comments
 (0)