3
votes

In my package.json file I've got script entry that runs graphql-codegen but it complains that the --config argument is invalid:

$> 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.

Since I believe the default file name is codegen.yml anyway, I try to run it with out that argument and nothing gets generated:

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

Any ideas?

6

6 Answers

5
votes

for me this solved the issue

Yarn

yarn add -D @graphql-codegen/cli

npm

npm i -D @graphql-codegen/cli

installation guide doc

2
votes

Ok, I'm not sure exactly what I did to fix this. I believe that I had also installed graphql-codegen globally and tried to uninstall it with sudo npm uninstall graphql-codegen which removed a bunch of packages but the executable still exists:

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

However I decided to run yarn graphql-codegen init on a whim to see if init was valid and because I couldn't remember if I hadn't tried that already. I got the set up questions like normal so I ctrl+C'ed and just ran yarn graphql-codegen and it worked! Then I ran yarn graphql-codegen --watch to test that it took options and that also worked.

If anyone gets this issue, I hope these tips help you.

2
votes

Try it: rm -rf ./node_modules && npm install

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

remove files or directories
-f, --force ignore nonexistent files and arguments, never prompt
-r, -R, --recursive remove directories and their contents recursively

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

You can think of the node_modules folder like a cache for the external modules that your project depends upon. When you npm install them, they are downloaded from the web and copied into the node_modules folder and nodejs is trained to look for them there when you import them (without a specific path).

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

This command installs a package and any packages that it depends on. If the package has a package-lock, or an npm shrinkwrap file, or a yarn lock file, the installation of dependencies will be driven by that, respecting the following order of precedence:

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

For me the solution was to install @graphql-codegen/cli.

0
votes

graphql.config.yml

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

package.json

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

Might also be that you have apollo's graphql-codegen package installed, which also exposes a binary called graphql-codegen, which accepts args schema and output, but not config.