apollographql / apollo-tooling

✏️ Apollo CLI for client tooling (Mostly replaced by Rover)
https://apollographql.com
MIT License
3.04k stars 470 forks source link

Error output of `codegen:generate` is absurdly verbose #1297

Open toolness opened 5 years ago

toolness commented 5 years ago

In version 2.12.3, running the following with a GraphQL file that has a validation error in it:

$ apollo codegen:generate --includes 'frontend/lib/queries/*.graphql' --localSchemaFile schema.json --target typescript --no-addTypename --outputFlat frontend/lib/queries/__generated__

produces the following output:

.../frontend/lib/queries/PasswordResetMutation.graphql: Cannot query field "LOLerrors" on type "PasswordResetPayload". Did you mean "errors"?
{ ToolError: Validation of GraphQL query document failed
    at Object.validateQueryDocument (/tenants2/node_modules/apollo-language-server/lib/errors/validation.js:32:19)
    at Object.generate [as default] (/tenants2/node_modules/apollo/lib/generate.js:22:18)
    at write (/tenants2/node_modules/apollo/lib/commands/client/codegen.js:67:54)
    at Task.task (/tenants2/node_modules/apollo/lib/commands/client/codegen.js:86:46)
    at <anonymous> name: 'ToolError' }
  ✔ Loading Apollo Project
  ✖ Generating query files with 'typescript' target
    → Validation of GraphQL query document failed
.../frontend/lib/queries/PasswordResetMutation.graphql: Cannot query field "LOLerrors" on type "PasswordResetPayload". Did you mean "errors"?
{ ToolError: Validation of GraphQL query document failed
    at Object.validateQueryDocument (/tenants2/node_modules/apollo-language-server/lib/errors/validation.js:32:19)
    at Object.generate [as default] (/tenants2/node_modules/apollo/lib/generate.js:22:18)
    at write (/tenants2/node_modules/apollo/lib/commands/client/codegen.js:67:54)
    at GraphQLClientProject.project.onDiagnostics [as _onDiagnostics] (/tenants2/node_modules/apollo/lib/commands/client/codegen.js:84:29)
    at GraphQLClientProject.validate (/tenants2/node_modules/apollo-language-server/lib/project/client.js:132:18)
    at GraphQLClientProject.validateIfNeeded (/tenants2/node_modules/apollo-language-server/lib/project/base.js:135:14)
    at Timeout.setTimeout [as _onTimeout] (/tenants2/node_modules/apollo-language-server/lib/project/base.js:127:22)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5) name: 'ToolError' }
(node:117) UnhandledPromiseRejectionWarning: ToolError: Validation of GraphQL query document failed
    at Object.validateQueryDocument (/tenants2/node_modules/apollo-language-server/lib/errors/validation.js:32:19)
    at Object.generate [as default] (/tenants2/node_modules/apollo/lib/generate.js:22:18)
    at write (/tenants2/node_modules/apollo/lib/commands/client/codegen.js:67:54)
    at GraphQLClientProject.project.onDiagnostics [as _onDiagnostics] (/tenants2/node_modules/apollo/lib/commands/client/codegen.js:84:29)
    at GraphQLClientProject.validate (/tenants2/node_modules/apollo-language-server/lib/project/client.js:132:18)
    at GraphQLClientProject.validateIfNeeded (/tenants2/node_modules/apollo-language-server/lib/project/base.js:135:14)
    at Timeout.setTimeout [as _onTimeout] (/tenants2/node_modules/apollo-language-server/lib/project/base.js:127:22)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)
(node:117) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
(node:117) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ToolError: Validation of GraphQL query document failed
    at Object.validateQueryDocument (/tenants2/node_modules/apollo-language-server/lib/errors/validation.js:32:19)
    at Object.generate [as default] (/tenants2/node_modules/apollo/lib/generate.js:22:18)
    at write (/tenants2/node_modules/apollo/lib/commands/client/codegen.js:67:54)
    at Task.task (/tenants2/node_modules/apollo/lib/commands/client/codegen.js:86:46)
    at <anonymous>

This is extremely verbose and the only line that's really important is the very first one. The DeprecationWarnings are also concerning.

trevor-scheer commented 5 years ago

Hey @toolness, thanks for submitting this. This is a reasonable request, however I think keeping the stack trace accessible is important for debugging purposes. We use a pattern within the codebase for printing debug info via this.debug('...') that should be sufficient. We'd be open to a PR that makes this change!

jckw commented 5 years ago

Seems like an odd choice to make the default level so verbose. Would it be more sensible to pass a --verbose flag to get the level needed for debugging codegen itself?

Debugging typos is particularly painful with this much output.