【问题标题】:graphql-codegen not running with config filegraphql-codegen 没有与配置文件一起运行
【发布时间】:2020-05-29 19:21:09
【问题描述】:

在我的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 graphql-codegen


    【解决方案1】:

    试试看:rm -rf ./node_modules && npm install

    rm http://manpages.ubuntu.com/manpages/trusty/man1/rm.1.html

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

    node_modules https://docs.npmjs.com/cli/v7/configuring-npm/folders

    您可以将 node_modules 文件夹视为缓存 对于您的项目所依赖的外部模块。当你 npm 安装它们,它们是从网上下载并复制到 node_modules 文件夹和 nodejs 被训练在那里寻找它们 您导入它们(没有特定路径)。

    npm install https://docs.npmjs.com/cli/install/

    这个命令安装一个包和它依赖的任何包。 如果包有一个包锁,或者一个 npm shrinkwrap 文件,或者一个 yarn lock 文件,依赖的安装将由 即,尊重以下优先顺序:

    • npm-shrinkwrap.json
    • package-lock.json
    • yarn.lock

    【讨论】:

      【解决方案2】:

      也可能是您安装了apollo's graphql-codegen package,它还公开了一个名为graphql-codegen 的二进制文件,它接受参数schemaoutput,但不接受config

      【讨论】:

      • 我正在使用它的 apollo 代码生成器,但我安装的确切软件包是:@graphql-codegen/cli@graphql-codegen/introspection@graphql-codegen/typescript@graphql-codegen/typescript-operations@graphql-codegen/typescript-react-apollo
      【解决方案3】:

      对我来说,这解决了问题

      纱线

      yarn add -D @graphql-codegen/cli
      

      npm

      npm i -D @graphql-codegen/cli
      

      installation guide doc

      【讨论】:

        【解决方案4】:

        graphql.config.yml

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

        package.json

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

        【讨论】:

          【解决方案5】:

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

          【讨论】:

            【解决方案6】:

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

            $>which graphql-codegen
            /usr/bin/graphql-codegen
            

            然而,我决定一时兴起运行yarn graphql-codegen init 以查看init 是否有效,因为我不记得我是否已经尝试过了。我遇到了正常的设置问题,所以我ctrl+C'ed 并运行了yarn graphql-codegen,它成功了!然后我运行yarn graphql-codegen --watch 来测试它是否接受了选项并且也有效。

            如果有人遇到此问题,希望这些提示对您有所帮助。

            【讨论】:

              猜你喜欢
              • 2021-07-30
              • 2017-11-23
              • 1970-01-01
              • 1970-01-01
              • 2021-05-05
              • 2019-08-03
              • 2019-02-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多