You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
If an Array<FragmentType<T>> is provided as the data to useFragment(T, data) then the returned value is always ReadonlyArray<DocumentType<T>> which can cause downstream issues with react components and functions that do not expect readonly values.
This is especially true when adding client-preset usage to an existing project.
Example:
import{FragmentType,graphql,useFragment}from"@/gql";constApp_Fragment=graphql(` fragment App_Fragment on Foo { value }`);typeAppProps={foos: Array<FragmentType<typeofApp_Fragment>>;};functionApp(props: AppProps){constfoosFragments=useFragment(App_Fragment,props.foos);// ReadonlyArray<App_FragmentFragment>constresult=doThing(foosFragments);// ERROR: The type 'readonly App_FragmentFragment[]' is 'readonly' and cannot be assigned to the mutable type 'App_FragmentFragment[]'return<MyComponentfoos={foosFragments}/>;// ERROR: The type 'readonly App_FragmentFragment[]' is 'readonly' and cannot be assigned to the mutable type 'App_FragmentFragment[]'}typeMyComponentProps={foos: Array<App_FragmentFragment>};
Describe the solution you'd like
useFragmentData() should return type Array<DocumentType<T>> when the data is an Array<FragmentType<T>> and should retain the readonly property when the data is a ReadonlyArray<FragmentType<T>>.
Describe alternatives you've considered
Updating all downstream usages to be ReadonlyArray<T>
client-preset shouldn't be opinionated on the immutability of types. Applying ReadonlyArray to downstream usages can cause significant development overhead in large projects.
Is your feature request related to a problem? Please describe.
No response
The text was updated successfully, but these errors were encountered:
rachel-church
changed the title
[client-preset] useFragmentData() shouldn't always return a ReadonlyArray when given an array
[client-preset] useFragment() shouldn't always return a ReadonlyArray when given an array
Jan 3, 2024
Is your feature request related to a problem? Please describe.
If an
Array<FragmentType<T>>
is provided as the data touseFragment(T, data)
then the returned value is alwaysReadonlyArray<DocumentType<T>>
which can cause downstream issues with react components and functions that do not expect readonly values.This is especially true when adding
client-preset
usage to an existing project.Example:
Describe the solution you'd like
useFragmentData()
should return typeArray<DocumentType<T>>
when the data is anArray<FragmentType<T>>
and should retain the readonly property when the data is aReadonlyArray<FragmentType<T>>
.Describe alternatives you've considered
Updating all downstream usages to be
ReadonlyArray<T>
client-preset
shouldn't be opinionated on the immutability of types. Applying ReadonlyArray to downstream usages can cause significant development overhead in large projects.Is your feature request related to a problem? Please describe.
No response
The text was updated successfully, but these errors were encountered: