apollographql / apollographql/apollo-tooling

Error output of `codegen:generate` is absurdly verbose

Open
#1,297 2 comments 3 reactions 0 assignees View on GitHub
:x: errors 🤖 component - codegen
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

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 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
```

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

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the shown apollo codegen:generate command, then inspect apollo-language-server/lib/errors/validation.js, apollo/lib/generate.js, and apollo/lib/commands/client/codegen.js from the reported stack traces. Done means validation failures show the useful diagnostic without repeated stack traces or unhandled-rejection warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.