graphql codegen 能否为 hooks 的结果数据字段自动生成类型?
Can graphql codegen automatically generate types for hooks' result data field?
我正在使用 graphql 代码生成挂钩,其结果类型为: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
执行此操作的最佳方法是在构建查询时使用片段。将为每个片段生成类型,然后可以直接使用它们。
我正在使用 graphql 代码生成挂钩,其结果类型为: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
执行此操作的最佳方法是在构建查询时使用片段。将为每个片段生成类型,然后可以直接使用它们。