Utilizing codegen, I automatically generate TypeScript types and employ Apollo client to submit requests to the server.
However, when I execute code generation for the given example, TypeScript fails to recognize that the people
object contains firstName
and lastName
fields. It only acknowledges the presence of the avatar
field. The issue can be resolved by eliminating the fragment and directly including the fields in the query.
How can I ensure proper support for fragments in this scenario?
fragments/person.graphql
fragment NameParts on Person {
firstName
lastName
}
queries/person.ts
import { graphql } from '@/gql'
export const getPersonDocument = graphql(`
query GetPerson {
people(id: "7") {
...NameParts
avatar(size: LARGE)
}
}
`)
'@/gql'
denotes the output directory of codegen