I use codegen to generate TS types and I use Apollo client to send queries to server.
when I generate code for the following example, Typescript dosen't know that people has firstName and lastName fields, It only knows that avatar field exists. If I remove fragment and move fields directly to query all fields are usable.
What should I do to support fragments correctly?
fragment NameParts on Person {
firstName
lastName
}
import { graphql } from '@/gql'
export const getPersonDocument = graphql(`
query GetPerson {
people(id: "7") {
...NameParts
avatar(size: LARGE)
}
}
`)
'@/gql' is the output directory of codegen
I set fragmentMasking: false to fix the problem
generates: {
'./src/gql/': {
preset: 'client',
presetConfig: {
fragmentMasking: false,
},
},
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With