Apollo-tooling: Cannot generate typescript definitions

Created on 28 Oct 2018  Â·  3Comments  Â·  Source: apollographql/apollo-tooling

I'm trying to migrate from the old apollo-codegen project to apollo-cli, but I can't seem to make it work.

When I run apollo codegen:generate I get the following error:

apollo codegen:generate --target typescript --queries=query.graphql
 ✔ Loading Apollo config
 ✔ Scanning for GraphQL queries (1 found)
 ✖ Generating query files with 'typescript' target
   → Cannot read property 'getQueryType' of undefined
TypeError: Cannot read property 'getQueryType' of undefined
    at TypeInfo.enter (~/Projects/arthens/apollo-cli-bug/node_modules/graphql/utilities/TypeInfo.js:142:25)
    at Object.enter (~/Projects/arthens/apollo-cli-bug/node_modules/graphql/language/visitor.js:363:16)
    at Object.visit (~/Projects/arthens/apollo-cli-bug/node_modules/graphql/language/visitor.js:254:26)
    at getValidationErrors (~/Projects/arthens/apollo-cli-bug/node_modules/apollo/lib/validation.js:21:15)
    at Object.validateQueryDocument (~/Projects/arthens/apollo-cli-bug/node_modules/apollo/lib/validation.js:26:30)
    at Object.generate [as default] (~/Projects/arthens/apollo-cli-bug/node_modules/apollo/lib/generate.js:19:18)
    at Task.task (~/Projects/arthens/apollo-cli-bug/node_modules/apollo/lib/commands/codegen/generate.js:98:64)
    at Promise.resolve.then.then.skipped (~/Projects/arthens/apollo-cli-bug/node_modules/listr/lib/task.js:167:30)
    at <anonymous>

This using apollo 1.9.2, but i tried 1.10.0-register.0 too and I still got the error.

You should be able to reproduce it by checking out https://github.com/arthens/apollo-cli-bug and running apollo codegen:generate --target typescript --queries=query.graphql

🤖 codegen

Most helpful comment

apollo service:download src/graphql/schema.json && apollo client:codegen \
--target typescript \
--localSchemaFile src/graphql/schema.json \
--includes ./src/**/*.gql

or

apollo client:codegen \ --endpoint http://localhost:4000 \ --includes src/**/*.gql \ --target typescript

both work for me. maybe that helps.

All 3 comments

@arthens you need to specify the location of the schema.

apollo codegen:generate --clientSchema schema.graphql --target typescript --queries=query.graphql
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Note that the GraphQL schema in your provided example is invalid (Company is not defined, but is referenced in CurrentUser), so you'll have to fix that as well.

apollo service:download src/graphql/schema.json && apollo client:codegen \
--target typescript \
--localSchemaFile src/graphql/schema.json \
--includes ./src/**/*.gql

or

apollo client:codegen \ --endpoint http://localhost:4000 \ --includes src/**/*.gql \ --target typescript

both work for me. maybe that helps.

@arthens this issue looks stale, so I'm going to close. If this is still an issue with the newest CLI, I can reopen :)

Was this page helpful?
0 / 5 - 0 ratings