我正在使用graphql codegen挂钩,其结果为:ApolloReactCommon.QueryResult
类型,这意味着它是具有data
,loading
和error
字段的对象。
通常,我将在需要定义其类型的其他组件中使用data
。我目前需要编写类似这样的内容以获取data
类型:
type MyPost = MyPostQueryHookResult['data']
我希望为我创建此MyPost
类型。有没有办法让它自动生成?
我的配置:
generates:
src/generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
config:
withHooks: true
最佳方法是在构建查询时使用片段。将为每个片段生成类型,然后可以直接使用它们。