You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行graphql-codegen命令提示找不到配置文件,配置哪里出错了?

问题原因及修复方案

核心问题1:命令参数使用了中文破折号

你的package.json中graphql:codegen脚本里的参数用了中文长破折号(—),而GraphQL Codegen CLI仅识别英文双破折号(--),这会导致CLI无法正确解析config参数,进而找不到配置文件。

修复脚本:

将package.json中的脚本修改为:

"scripts": {
    "graphql:codegen": "graphql-codegen --config graphql-codegen.yml"
},
"dependencies": {
    "@apollo/client": "^3.7.0",
    "@emotion/core": "^10.0.21",
    "@graphql-codegen/cli": "^2.16.2",
    "@graphql-codegen/fragment-matcher": "^3.3.3",
    "@graphql-codegen/typescript": "^2.8.6",
    "@graphql-codegen/typescript-operations": "^2.5.11",
    "@graphql-codegen/typescript-react-apollo": "^3.3.7"
}

核心问题2:配置文件中的列表符号用了中文破折号

你的graphql-codegen.yml里plugins下的列表项使用了中文长破折号(—),YAML语法要求必须用英文短破折号(-),否则配置文件会解析失败,即使CLI找到文件也无法正常执行。

修复配置文件:

将graphql-codegen.yml修改为:

schema: "https://swapi-graphql.netlify.app/.netlify/functions/index"
overwrite: true
documents: "src/**/*.graphql"
generates:
  src/generated/graphql-types.tsx:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-apollo"

验证步骤

  1. 保存上述两处修改
  2. 重新执行yarn graphql:codegen命令

这样就能正常识别配置文件并生成对应的GraphQL类型代码了。

内容的提问来源于stack exchange,提问作者Morton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 18:05:32