graphql-codegen not running with config file
Asked Answered
I

9

18

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?

Iciness answered 14/2, 2020 at 1:22 Comment(0)
I
5

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.

Iciness answered 14/2, 2020 at 18:20 Comment(0)
F
19

for me this solved the issue

Yarn

yarn add -D @graphql-codegen/cli

npm

npm i -D @graphql-codegen/cli

installation guide doc

Foreskin answered 18/8, 2020 at 8:5 Comment(0)
I
5

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.

Iciness answered 14/2, 2020 at 18:20 Comment(0)
T
5

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
Trossachs answered 4/4, 2021 at 18:34 Comment(0)
V
4

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.

Vermillion answered 11/3, 2021 at 21:6 Comment(1)
Well its apollo's code gen that I am using but the exact packages I have installed are: @graphql-codegen/cli, @graphql-codegen/introspection, @graphql-codegen/typescript, @graphql-codegen/typescript-operations, @graphql-codegen/typescript-react-apollo.Iciness
A
2

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

Alphorn answered 14/5, 2020 at 9:34 Comment(0)
H
0

graphql.config.yml

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

package.json

{
   "codegen": "graphql codegen --config graphql.config.yml"
}
Hydrotherapy answered 9/6, 2020 at 15:5 Comment(0)
M
0

I've fixed the problem by using graphql-code-generator instead:

"scripts": {
    "graphql:generate": "graphql-code-generator"
}
Mustang answered 16/12, 2022 at 8:21 Comment(0)
W
0

in my case i removed the space before the file name, so: codegen.ts instead of codegen.ts

Wendelina answered 8/8, 2023 at 22:57 Comment(0)
H
0

Please try to remove the lib:

yarn remove graphql-codegen
rm -rf node_modules

codegen.ts file

import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  schema: "http://localhost:8081/graphql",
  documents: ["src/**/*.tsx"],
  generates: {
    "./src/__generated__/": {
      preset: "client",
      presetConfig: {
        gqlTagName: "gql",
      },
    },
  },
  ignoreNoDocuments: true,
};

export default config;
Hairdresser answered 2/1 at 20:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.