Infer fragment type without useFragment #8420
Answered
by
charlypoly
jeffreyyoung
asked this question in
General
-
Is it possible to infer the type of a typed document node in pure typescript without calling for example I'd like something like this: import { Infer } from './gql/fragment-masking';
export const FilmFragment = graphql(/* GraphQL */ `
fragment FilmItem on Film {
id
title
}
`)
// I want to infer type without invoking useFragment
type InferredType = Infer<typeof FilmFragment>;
// { id: string, title: string }!! |
Beta Was this translation helpful? Give feedback.
Answered by
charlypoly
Oct 3, 2022
Replies: 1 comment
-
Hi @jeffreyyoung, You can get the fragment type by using the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
charlypoly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @jeffreyyoung,
You can get the fragment type by using the
FragmentType<typeof FragmentDocument>
type helper, as shown in our docs: https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue#writing-graphql-fragments