Skip to content

client:codegen failing when run with npx/yarn #881

@lsanwick

Description

@lsanwick

I'm seeing strange errors when attempting to run apollo client:codegen under yarn/npm instead of just running a globally installed version.

I've verified that the node version and apollo version are the same in both instances, see my shell log below:

It works successfully when I run it via a globally installed apollo (i.e. from yarn global add apollo)

$> apollo client:codegen __types__ --target=typescript
 ✔ Loading Apollo Project
 ✔ Generating query files with 'typescript' target - wrote 2 files

If I run the same command via npx, it fails.

$> npx apollo client:codegen __types__ --target=typescript
  ✔ Loading Apollo Project
  ✖ Generating query files with 'typescript' target
    → Cannot query field "user" on type "Query"
(node:32387) UnhandledPromiseRejectionWarning: GraphQLError: Cannot query field "user" on type "Query"
    at Compiler.compileSelection (/Users/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:119:27)
    at selections.selectionSetNode.selections.map.selectionNode (/Users/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:106:76)
    at Array.map (<anonymous>)
    at Compiler.compileSelectionSet (/Users/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:106:18)
    at Compiler.compileOperation (/Users/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:86:32)
    at Object.compileToIR (/Users/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:15:44)
    at Object.generate [as default] (/Users/<PROJECT>/node_modules/apollo/lib/generate.js:75:36)
    at write (/Users/<PROJECT>/node_modules/apollo/lib/commands/client/codegen.js:67:42)
    at GraphQLClientProject.project.onDiagnostics [as _onDiagnostics] (/Users/<PROJECT>/node_modules/apollo/lib/commands/client/codegen.js:91:17)
    at GraphQLClientProject.validate (/Users/<PROJECT>/node_modules/apollo-language-server/lib/project/client.js:102:18)
(node:32387) 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: 3)
(node:32387) [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.
GraphQLError: Cannot query field "user" on type "Query"
    at Compiler.compileSelection (~/Documents/repos/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:119:27)
    at selections.selectionSetNode.selections.map.selectionNode (~/Documents/repos/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:106:76)
    at Array.map (<anonymous>)
    at Compiler.compileSelectionSet (~/Documents/repos/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:106:18)
    at Compiler.compileOperation (~/Documents/repos/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:86:32)
    at Object.compileToIR (~/Documents/repos/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:15:44)
    at Object.generate [as default] (~/Documents/repos/<PROJECT>/node_modules/apollo/lib/generate.js:75:36)
    at write (~/Documents/repos/<PROJECT>/node_modules/apollo/lib/commands/client/codegen.js:67:42)
    at Task.task (~/Documents/repos/<PROJECT>/node_modules/apollo/lib/commands/client/codegen.js:93:36)

Same thing when using yarn.

$> yarn run apollo client:codegen __types__ --target=typescript
yarn run v1.12.3
$ /Users/<PROJECT>/node_modules/.bin/apollo client:codegen __types__ --target=typescript
  ✔ Loading Apollo Project
  ✖ Generating query files with 'typescript' target
    → Cannot query field "user" on type "Query"
(node:32548) UnhandledPromiseRejectionWarning: GraphQLError: Cannot query field "user" on type "Query"
    at Compiler.compileSelection (/Users/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:119:27)
    at selections.selectionSetNode.selections.map.selectionNode (/Users/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:106:76)
    at Array.map (<anonymous>)
    at Compiler.compileSelectionSet (/Users/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:106:18)
    at Compiler.compileOperation (/Users/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:86:32)
    at Object.compileToIR (/Users/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:15:44)
    at Object.generate [as default] (/Users/<PROJECT>/node_modules/apollo/lib/generate.js:75:36)
    at write (/Users/<PROJECT>/node_modules/apollo/lib/commands/client/codegen.js:67:42)
    at GraphQLClientProject.project.onDiagnostics [as _onDiagnostics] (/Users/<PROJECT>/node_modules/apollo/lib/commands/client/codegen.js:91:17)
    at GraphQLClientProject.validate (/Users/<PROJECT>/node_modules/apollo-language-server/lib/project/client.js:102:18)
(node:32548) 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: 3)
(node:32548) [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.
GraphQLError: Cannot query field "user" on type "Query"
    at Compiler.compileSelection (~/Documents/repos/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:119:27)
    at selections.selectionSetNode.selections.map.selectionNode (~/Documents/repos/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:106:76)
    at Array.map (<anonymous>)
    at Compiler.compileSelectionSet (~/Documents/repos/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:106:18)
    at Compiler.compileOperation (~/Documents/repos/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:86:32)
    at Object.compileToIR (~/Documents/repos/<PROJECT>/node_modules/apollo-codegen-core/lib/compiler/index.js:15:44)
    at Object.generate [as default] (~/Documents/repos/<PROJECT>/node_modules/apollo/lib/generate.js:75:36)
    at write (~/Documents/repos/<PROJECT>/node_modules/apollo/lib/commands/client/codegen.js:67:42)
    at Task.task (~/Documents/repos/<PROJECT>/node_modules/apollo/lib/commands/client/codegen.js:93:36)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The versions appear identical in either mode, as far as I can tell.

$> apollo --version
apollo/2.1.9 darwin-x64 node-v10.14.1
$> yarn run apollo --version
yarn run v1.12.3
$ /Users/<PROJECT>/node_modules/.bin/apollo --version
apollo/2.1.9 darwin-x64 node-v10.14.1
✨  Done in 0.29s.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions