Apollo-tooling: Typescript: Mutations with scalar return type

Created on 29 Jul 2017  路  16Comments  路  Source: apollographql/apollo-tooling

_When trying to generate typescript code for a mutation that returns some SCALAR type, an exception is thrown._

Intended outcome: Code for mutations with SCALAR return types is properly generated

Actual outcome: The following exception is thrown:
TypeError: Cannot read property 'map' of undefined at fields.map.rootField (xxx\apollo-codegen\src\typescript\codeGeneration.js:153:36) at Array.map (native) at interfaceDeclarationForOperation (xxx\apollo-codegen\src\typescript\codeGeneration.js:152:19) at Object.values.forEach.operation (xxx\apollo-codegen\src\typescript\codeGeneration.js:47:5) at Array.forEach (native) at Object.generateSource (xxx\apollo-codegen\src\typescript\codeGeneration.js:45:37) at Object.generate (xxx\apollo-codegen\src\generate.ts:42:16) at Object.yargs.command.command.command.argv [as handler] (xxx\apollo-codegen\src\cli.js:183:7) at Object.self.runCommand (xxx\apollo-codegen\node_modules\yargs\lib\command.js:233:22) at Object.Yargs.self._parseArgs (xxx\apollo-codegen\node_modules\yargs\yargs.js:990:30)

How to reproduce the issue:

  1. In the schema, define a mutation with some SCALAR return type, e.g., Boolean
  2. Define a graphql file or gql-embedded mutation
  3. Try to generate typescript code for the graphql file or ts file containing the gql-tag:
    apollo-codegen generate test.graphql --schema test.json --addTypename --target typescript --output types.ts

_Example files are attached:_
test.zip

馃悶 bug

Most helpful comment

@yuricamara apologies for the delay, I've been really busy with other work. trying to put more work in asap

All 16 comments

I believe this is a bug due to https://github.com/apollographql/apollo-codegen/pull/188, triggered because the code on this line assumes root fields cannot be scalars.

@martijnwalraven yup, I'll try to fix that ASAP!

Same problem here when using version 0.16.

I tried the following versions: v0.15.2, v0.16.0, v0.16.1 and v0.16.5. It only worked to the first one.

Same issue for me

We encountered the same error when generating Flow types. We have a root-level query that returns a scalar.

type RootQuery {
  someValue: Float!
}

@rricard , any news about this issue?

@lewisf is rewriting the Flow and TypeScript targets with the new codegen compiler, and I expect that will fix this issue.

Is there a release forecast for this work?

@yuricamara apologies for the delay, I've been really busy with other work. trying to put more work in asap

Do not worry. We know you're doing the best you can, @lewisf

This ticket should be closed because the problem was solved at least in apollo-codegen 0.18.3, possibly even much earlier in https://github.com/apollographql/apollo-codegen/commit/9bd37a9a1a2ececfaa5d92be47ea7bcb2d4ddf27.

I got the same error.

apollo-codegen 0.18.8

apollo-codegen generate --schema schema.json --output API.swift

TypeError: Cannot read property 'length' of undefined
    at Object.yargs.command.command.command.argv [as handler] (/usr/local/lib/node_modules/apollo-codegen/src/cli.js:186:17)
    at Object.runCommand (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/lib/command.js:235:44)
    at Object.parseArgs [as _parseArgs] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:1013:30)
    at Object.get [as argv] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:957:21)
    at Object.<anonymous> (/usr/local/lib/node_modules/apollo-codegen/lib/cli.js:197:5)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

I got the same error here.

Version

0.19.1

Command

apollo-codegen generate --schema schema.json --output API.swift

Output

TypeError: Cannot read property 'length' of undefined
    at Object.yargs.command.command.command.argv [as handler] (/usr/local/lib/node_modules/apollo-codegen/src/cli.js:186:17)
    at Object.runCommand (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/lib/command.js:235:44)
    at Object.parseArgs [as _parseArgs] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:1013:30)
    at Object.get [as argv] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:957:21)
    at Object.<anonymous> (/usr/local/lib/node_modules/apollo-codegen/lib/cli.js:197:5)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)

@ZZHHAANNGG and @JulienBreux latest comments both output swift and not typescript. It is unrelated to the original issue. The actual error message is not even the same.

@knorzel, could you please close this issue ?

@PowerKiKi need to open a new issue?

If you are experiencing a bug with the latest version of the lib and it has not been reported already, then you should report it and include a reproduction case as well as the error seen.

Was this page helpful?
0 / 5 - 0 ratings