graphql代码生成器可以自动为挂钩的结果数据字段生成类型吗?

问题描述 投票:1回答:1

我正在使用graphql codegen挂钩,其结果为:ApolloReactCommon.QueryResult类型,这意味着它是具有dataloadingerror字段的对象。

通常,我将在需要定义其类型的其他组件中使用data。我目前需要编写类似这样的内容以获取data类型:

type MyPost = MyPostQueryHookResult['data']

我希望为我创建此MyPost类型。有没有办法让它自动生成?

我的配置:

generates:
  src/generated/graphql.tsx:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-apollo"
    config:
      withHooks: true
typescript graphql codegen
1个回答
0
投票

最佳方法是在构建查询时使用片段。将为每个片段生成类型,然后可以直接使用它们。

来源:from the main contributor of graphql-codegen

© www.soinside.com 2019 - 2024. All rights reserved.