graphql codegen未使用配置文件运行

graphql codegen未使用配置文件运行,graphql,graphql-codegen,Graphql,Graphql Codegen,在我的package.json文件中,我有一个运行graphql codegen的脚本条目,但它抱怨--config参数无效: $> yarn gen yarn run v1.21.1 $ graphql-codegen --config codegen.yml Error: Unknown argument: config ... error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/c

在我的
package.json
文件中,我有一个运行
graphql codegen
的脚本条目,但它抱怨
--config
参数无效:

$> yarn gen
yarn run v1.21.1
$ graphql-codegen --config codegen.yml
Error: Unknown argument: config
...
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
因为我相信默认文件名是
codegen.yml
,所以我尝试在不使用该参数的情况下运行它,但没有生成任何内容:

$> yarn graphql-codegen
yarn run v1.21.1
$ /home/aaron/projects/my_app/node_modules/.bin/graphql-codegen
Done in 0.17s.

有什么想法吗?

好的,我不确定我到底做了什么来解决这个问题。我相信我也在全球范围内安装了
graphql-codegen
,并尝试使用
sudo-npm-uninstall-graphql-codegen
卸载它,它删除了一系列软件包,但可执行文件仍然存在:

$>which graphql-codegen
/usr/bin/graphql-codegen
然而,我一时兴起,决定运行
warn-graphql-codegen-init
,看看
init
是否有效,因为我记不起是否已经尝试过了。我像普通人一样得到了设置问题,所以我
ctrl+C
,然后运行
纱线图ql codegen
,结果成功了!然后我运行了
纱线图qlcodegen--watch
来测试它是否有选项,并且也能正常工作


如果有人遇到这个问题,我希望这些提示能帮助您。

对我来说,解决方案是安装@graphql codegen/cli。

graphql.config.yml

schema: http://localhost:8081/graphql
extensions:
  codegen:
    generates:
      ./schema.graphql:
        - schema-ast
package.json

{
   "codegen": "graphql codegen --config graphql.config.yml"
}

对我来说,这解决了问题

纱线

npm


也可能是您已经安装的,它还公开了一个名为
graphql codegen
的二进制文件,它接受args
schema
output
,但不接受
config
试试看:
rm-rf./node\u模块和&npm安装

rm

删除文件或目录
-f,--force忽略不存在的文件和参数,从不提示
-r,-r,--recursive递归删除目录及其内容

节点\u模块

您可以将node_modules文件夹视为缓存 对于项目所依赖的外部模块。当你npm 安装它们后,它们将从web下载并复制到 node_modules文件夹和nodejs经过培训,可以在 您可以导入它们(无特定路径)

npm安装

此命令安装程序包及其所依赖的任何程序包。 如果包具有包锁、npm包覆面提取文件或 纱线锁文件,安装依赖将由驱动 根据以下优先顺序:

  • npm-shrinkwrap.json
  • package-lock.json
  • 纱线锁

npm i-D@graphql-codegen/cli
在我使用的阿波罗密码机上做得太好了,但我安装的确切软件包是:
@graphql-codegen/cli
@graphql-codegen/introspection
@graphql-codegen/typscript-operations
@graphql-codegen/typescript-react-apollo
yarn add -D @graphql-codegen/cli
npm i -D @graphql-codegen/cli