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
When there are a fragment embedded in another framgnet to same object, trying to pass whole array of fragment that returned from useFragment to another FragmentType<>[] prop, type error occors.
exportconstFilmContainerFragment=graphql(/* GraphQL */` fragment FilmContainer on Film { id title ...FilmDetails }`)constFilmList=(props: {film: FragmentType<typeofFilmContainerFragment>[]})=>{constfilm=useFragment(FilmContainerFragment,props.film)console.log(film[0].title)// The type 'readonly FilmContainerFragment[]' is 'readonly' and cannot be assigned to the mutable type '{ ' $fragmentRefs'?: { FilmDetailsFragment: FilmDetailsFragment; }; }[]'.(4104)// App.tsx(33, 3): The expected type comes from property 'film' which is declared here on type '{ film: { ' $fragmentRefs'?: { FilmDetailsFragment: FilmDetailsFragment; }; }[]; }'FilmDetails({film: film})// FilmContainerFragment[] itself is completely satisfied the type FragmentType<typeof FilmDetailsFragment>[]// but useFragment() adds extra 'readonly []' breaks the satisfactionconstassert1: FilmContainerFragmentType[]extendsFragmentType<typeofFilmDetailsFragment>[]
? true
: false=trueconstassert2: readonlyFilmContainerFragmentType[]extendsFragmentType<typeofFilmDetailsFragment>[]
? true
: false=false// FilmContainerFragment[] can expanded to// ( { __typename?: 'Film', id: string, title?: string | null }// & { ' $fragmentRefs'?: { 'FilmDetailsFragment': FilmDetailsFragment } }// ) & { ' $fragmentName'?: 'FilmContainerFragment' }[]// FragmentType<typeof FilmDetailsFragment>[] can expanded to// { ' $fragmentRefs'?: { 'FilmDetailsFragment': FilmDetailsFragment } }[]}exportconstFilmDetailsFragment=graphql(/* GraphQL */` fragment FilmDetails on Film { id title releaseDate producers }`)constFilmDetails=(props: {film: FragmentType<typeofFilmDetailsFragment>[]// Add `readonly` before FragmneType<> can be workaround here// film: readonly FragmentType<typeof FilmDetailsFragment>[]})=>{constfilm=useFragment(FilmDetailsFragment,props.film)}
Which packages are impacted by your issue?
@graphql-codegen/client-preset
Describe the bug
When there are a fragment embedded in another framgnet to same object, trying to pass whole array of fragment that returned from useFragment to another FragmentType<>[] prop, type error occors.
Your Example Website or App
https://stackblitz.com/edit/github-qjbrdu?file=App.ts,codegen.ts,package.json
Steps to Reproduce the Bug or Issue
Expected behavior
It can pass whole fragment array to another component's FragmentType<> prop without type errors.
Screenshots or Videos
No response
Platform
graphql
version: 16.2.0@graphql-codegen/*
version(s): 4.2.5Codegen Config File
Additional context
No response
The text was updated successfully, but these errors were encountered: