Is your feature request related to a problem? Please describe.
Currently it's quite difficult to discern what exactly is going wrong if there's an error. Error messages are simply along the lines of: An error has occurred in one of your documents.
Describe the solution you'd like
I'd prefer the ability to either set a flag that makes it more verbose, or simply enable it by default to include the exact file and lines that are erroneous.
I'm having trouble with the download of a remote schema failing, and I don't know exactly what it's trying to download, nor do I know what the server is saying back. It'd be awesome if there was a --debug flag or something so I could see what it's doing to help me troubleshoot.
In https://github.com/dotansimha/graphql-code-generator/issues/953, @kroeder mentioned that it works fine with PowerShell instead of CMD, so I guess this issue is related only to Windows.
@wesselvdv @thekevinbrown do you use Windows as well?
*it works with power shell, not with git bash, using it as webstorm terminal (but on windows)
Just do be 100% exact :)
@dotansimha No, I'm on OS X.
The request is for a way to see what the tool is doing under the hood in the form of logs via some kind of --debug flag though, so I don't know what about that need is platform dependent.
@dotansimha Nope, i'm on macOS Mojave, and using PHPStorm terminal. I had to manually place some console.log statements to figure out where stuff was going awry. I almost seems as if the logging is cutoff at a newline, because only the start of an error message is shown.
@thekevinbrown makes sense, we had it before v0.14 and I think we need to add it back.
@wesselvdv @thekevinbrown which shell do you use? I'm also using Mac OS Mojave and I can see the errors using https://github.com/robbyrussell/oh-my-zsh shell.
@dotansimha I’m using bash
I'm on Windows - and the most I can get out of it is: Found 2 errors in your documents
I can see that the validator throws a DetailedError with actual detail - but I can't get the console to actually log it. (unless I hack the source)
Fixed in 0.15. Please re-open if the issue persist.
@dotansimha got the same issue on 0.15.1, output just says: → Found 2 errors in your documents
I'm on Mojave with on-my-zsh shell. Any suggestions?
@dotansimha update: we use concurrently package to run gql-gen and a couple of other tasks in parallel. It's not working with it, but a standalone command works fine.
Same situation here. Running in Concurrently hides the error details.
From a brief bit of investigation I think it’s when there’s no TTY to the process, the listr renderer behaves differently.
I don't think this issue is closed. If there's no TTY, the output remains unhelpful.
I'm using v0.16:
〉yarn list --pattern code-gen
yarn list v1.13.0
└─ [email protected]
✨ Done in 0.49s.
Running the generator gives me:
〉./node_modules/.bin/gql-gen
✔ Parse configuration
❯ Generate outputs
❯ Generate ./generated/types.ts
✔ Load GraphQL schemas
✔ Load GraphQL documents
✖ Generate
→ Found 1 error in your documents!
Found 1 error
✖ ./generated/types.ts
Error: Found 1 error in your documents!
Something went wrong
And removing the TTY doesn't tell me much else:
〉./node_modules/.bin/gql-gen | cat
[12:54:24] Parse configuration [started]
[12:54:24] Parse configuration [completed]
[12:54:24] Generate outputs [started]
[12:54:24] Generate ./generated/types.ts [started]
[12:54:24] Load GraphQL schemas [started]
[12:54:24] Load GraphQL schemas [completed]
[12:54:24] Load GraphQL documents [started]
[12:54:25] Load GraphQL documents [completed]
[12:54:25] Generate [started]
[12:54:25] Generate [failed]
[12:54:25] → Found 1 error in your documents!
[12:54:25] Generate ./generated/types.ts [failed]
[12:54:25] → Found 1 error in your documents!
[12:54:25] Generate outputs [failed]
Something went wrong
And my types file is never generated:
〉ls generated/types.ts
ls: generated/types.ts: No such file or directory
FWIW, I was able to figure out my bug by editing node_modules/graphql-code-generator/dist/execute-plugin.js and adding a console.log():

Then I was able to see:
[ { filePath: '../frontend/lib/queries.ts',
errors: [ [GraphQLError] ] } ]
✔ Parse configuration
❯ Generate outputs
The file queries.ts is currently this:
import { gql } from 'apollo-boost'
import { USER_PARTS } from './fragments'
export const WHO_AM_I = gql`
query WhoAmI {
me {
...UserParts
verified
}
}
${USER_PARTS}
`
The error was due to my adding a verified property to my GraphQL query. Removing that property in the query makes the code generator work. I would expect to see such an explanation in the error output.
I hope this is useful.
The code generator is awesome. Keep up the great work!
FWIW, I was able to figure out my bug by editing
node_modules/graphql-code-generator/dist/execute-plugin.jsand adding aconsole.log():
I changed your code to be console.log(JSON.stringify(errors)); so that I could see the expanded error messages.
Thanks @wesselvdv @statico @seamusv ! which version are you using?
Can you please provide a minimal schema, a document and a codegen.yml file that causes this? thank you!
I'm reopening. The console.log line should be in a different place, because we would like to print it with the file info and indent it correctly.
@dotansimha You can actually easily reproduce this by executing this without attaching an tty and then attaching to the output.
I am running gql-gen inside a alpine docker container so I had to manuslly designate a pseudo-tty to get logging output, not sure how to this in the terminal. Maybe running it in background? (&)
I Have the same issue. I've tracked the problem to checkValidationErrors in graphql-toolkit
Problem is in throw new Error("Found " + errorCount + " error" + (errorCount > 1 ? 's' : '') + " in your documents!");. The function collects the errors but does not pass them to the exception.
This did the trick for me:
throw new Error("Found " + errorCount + " error" + (errorCount > 1 ? 's' : '') + " in your documents!" + errors.join());
Should probably use https://github.com/sindresorhus/aggregate-error or something similar
errors.map(error => {
console.error(`Error in: ${error.filePath}`);
error.errors.map(e => {
console.error(`- ${e.message}`);
})
})
I wound up writing something like @williamluke4:
errors.forEach(file => {
console.warn(`${file.filePath}:`);
file.errors.forEach(e =>{
const locs = e.locations.map(l => `${l.line}:${l.column}`).join(", ")
console.warn(` ${e.message} (line ${locs})`);
})
})
Running with e.g. ./node_modules/.bin/gql-gen |less, this will present errors like this:
modules/client/graphql/queries/FooBar.graphql:
Variable "$baz is not defined by operation "FooBar". (line 2:15, 1:1)
Hopefully this helps others get unstuck, but for graphql-code-generator we should figure out how to present errors nicely both with and without a TTY.
For now, a quick and easy way to get _something_ in both scenarios is to catch the exception from graphql-toolkit's checkValidationErrors() and rethrow with more detail:
try {
graphql_toolkit_1.checkValidationErrors(errors);
} catch (e) {
const errorsString = errors.map(file => {
return ` ${file.filePath}:\n` +
file.errors.map(err => {
const locs = err.locations.map(l => `${l.line}:${l.column}`).join(", ")
return ` ${err.message} (line ${locs})`
}).join("\n")
}).join("\n")
throw new Error(errorsString)
}
This will be a nice addition. Thanks everyone for pointing solutions. This saved me. 😃
Good god please fix this. I love you guys but this makes be cry.
Thank you all and sorry for the inconvenience. @DAB0mB is working on a fix now :)
Fixed in graphql-toolkit, PR here: https://github.com/dotansimha/graphql-code-generator/pull/1370
I'm adding tests to codegen and then we can release
Fixed in 0.18.0 🎉
Most helpful comment
Good god please fix this. I love you guys but this makes be cry.