timqian / gql-generator

Generate queries from graphql schema, used for writing api test.
MIT License
375 stars 93 forks source link

BEWARE - this tool is dangerous. It will delete your files without the possibility of recovery #79

Open mborkland opened 6 months ago

mborkland commented 6 months ago

Wow, I never expected a GraphQL query generator to recursively delete a whole directory of files, but it did.

Steps to reproduce:

  1. Execute this command with a valid path to the schema: gqlg --schemaFilePath /path/to/schema --destDirPath .
  2. Get an error like this:
    
    /Users/user/.nvm/versions/node/v14.20.1/lib/node_modules/gql-generator/index.js:210
      if (err.code !== 'EEXIST') throw err;
                                 ^

Error: ENOENT: no such file or directory, mkdir 'queries' at Object.mkdirSync (fs.js:1014:3) at generateFile (/Users/user/.nvm/versions/node/v14.20.1/lib/node_modules/gql-generator/index.js:208:10) at main (/Users/user/.nvm/versions/node/v14.20.1/lib/node_modules/gql-generator/index.js:252:5) at Object. (/Users/user/.nvm/versions/node/v14.20.1/lib/node_modules/gql-generator/index.js:283:3) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:12) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) at internal/main/run_main_module.js:17:47 { errno: -2, syscall: 'mkdir', code: 'ENOENT', path: 'queries' }


3. Execute `ls -l` and your current directory will be empty, including the schema that you gave as an input!

I would like an explanation for why this happened. Thankfully, most of my work is in git, but I did have to redo a couple hours worth of updates I had made. It seems the tool does not support using the current directory as the destination directory, which is perplexing to me as a user. Please fix this bug or at least include a very strong warning in the README.