@graphql-codegen/typescript-react-query未生成useQuery对象格式代码
解决@graphql-codegen/typescript-react-query生成TanStack Query v5兼容的对象格式参数问题
你需要在配置中添加legacyMode: false来强制生成符合TanStack Query v5要求的对象式参数hooks,具体修改如下:
修改后的生成配置
"schema.ts": { plugins: [ "typescript", "typescript-operations", "typescript-react-query" ], config: { enumValues: enumValues, exposeDocument: true, exposeQueryKeys: true, exposeMutationKeys: true, exposeFetcher: true, addInfiniteQuery: true, legacyMode: false // 新增配置项,关闭兼容旧版的参数模式 } }
原因说明
@graphql-codegen/typescript-react-query v6版本默认开启legacyMode(值为true),会生成适配TanStack Query旧版本的位置参数格式hooks。而TanStack Query v5要求所有hooks使用对象式参数传递,因此需要显式关闭legacyMode,让代码生成器输出符合v5规范的hooks结构。
确认你的@graphql-codegen/typescript-react-query版本为v6.x,该配置项在这个版本中才正式支持适配TanStack Query v4/v5的对象参数模式。
内容的提问来源于stack exchange,提问作者user22997093
相关产品推荐
相关产品推荐

