Apollo-tooling: apollo codegen:generate did't work. TypeError: Cannot read property 'name' of undefined

Created on 9 Nov 2018  ·  13Comments  ·  Source: apollographql/apollo-tooling

I am trying codegen:generate with npm scripts.

  "scripts": {
    ...
    "precodegen": "apollo service:download --endpoint=http://localhost:4000/graphql",
    "codegen": "apollo codegen:generate src/types/api.d.ts --queries='src/**/*.query.ts' --addTypename --target typescript --outputFlat"
  },

But I faced error..

TypeError: Cannot read property 'name' of undefined
    at Object.exports.getServiceName (~/XXXXX/client/node_modules/apollo-language-server/lib/config.js:66:34)
    at new ApolloConfig (~/XXXXX/client/node_modules/apollo-language-server/lib/config.js:74:29)
    at Object.exports.loadConfig (~/XXXXX/client/node_modules/apollo-language-server/lib/config.js:154:22)
    at <anonymous>

~/XXXXX/client/node_modules/apollo-language-server/lib/config.js:66:34
image

Thanks!

Most helpful comment

Having the exact same issue.

All 13 comments

FYI>

Client packages

  "dependencies": {
    "antd": "3.10.3",
    "apollo": "2.0.8",
    "apollo-boost": "0.1.20",
    "graphql": "14.0.2",
    "react": "16.6.0",
    "react-apollo": "2.2.4",
    "react-dom": "16.6.0",
    "react-router-dom": "4.3.1",
    "react-scripts-ts": "3.1.0",
    "styled-components": "4.0.3",
    "styled-reset": "1.6.0"
  },
  "devDependencies": {
    "@types/jest": "^23.3.9",
    "@types/node": "^10.12.2",
    "@types/react": "^16.4.18",
    "@types/react-dom": "^16.0.9",
    "@types/react-router-dom": "^4.3.1",
    "@types/styled-components": "^4.0.3",
    "react-app-rewire-less": "^2.1.3",
    "react-app-rewired": "^1.6.2",
    "ts-import-plugin": "^1.5.5",
    "typescript": "^3.1.6"
  }

Server packages

  "devDependencies": {
    "@types/morgan": "^1.7.35",
    "@types/node": "^10.12.3",
    "babel-runtime": "^6.26.0",
    "gql-merge": "^0.0.6",
    "graphql-to-typescript": "^0.1.2",
    "nodemon": "^1.18.6",
    "ts-node": "^7.0.1",
    "tslint": "^5.11.0",
    "tslint-config-prettier": "^1.15.0",
    "typescript": "^3.1.6"
  },
  "dependencies": {
    "graphql-tools": "4.0.3",
    "graphql-yoga": "1.16.7",
    "merge-graphql-schemas": "1.5.7",
    "morgan": "1.9.1"
  }

Having the exact same issue.

Also running into this and unsure how to proceed.

It works at v1.9.2.... T^T

$ apollo codegen:generate src/types/api.d.ts --queries='src/**/*.query.ts' --addTypename --target typescript --outputFlat
 ›   Warning: apollo update available from 1.9.2 to 2.0.8
 ✔ Loading Apollo config
 ✔ Scanning for GraphQL queries (0 found)
 ✔ Generating query files with 'typescript' target - wrote 1 files

It works at v1.9.2.... T^T

$ apollo codegen:generate src/types/api.d.ts --queries='src/**/*.query.ts' --addTypename --target typescript --outputFlat
 ›   Warning: apollo update available from 1.9.2 to 2.0.8
 ✔ Loading Apollo config
 ✔ Scanning for GraphQL queries (0 found)
 ✔ Generating query files with 'typescript' target - wrote 1 files

Correct. worked with older version!

I believe this should have been fixed in the latest versions. Could you try again and see if that works for you?

I believe this should have been fixed in the latest versions. Could you try again and see if that works for you?

@martijnwalraven
It doesn't work yet...
I do not use a config file. Do I have to use the config file?

❯ yarn codegen
yarn run v1.12.1
$ apollo service:download --endpoint=http://localhost:4000/graphql
 ✔ Loading Apollo Project
 ✔ Saving schema to schema.json
$ apollo codegen:generate src/types/api.d.ts --queries='src/**/*.query.ts' --addTypename --target typescript --outputFlat
Error: No provider was created for config
    at Object.schemaProviderFromConfig (~/XXXXX/client/node_modules/apollo-language-server/lib/schema/providers/index.js:29:11)
    at new GraphQLProject (~/XXXXX/client/node_modules/apollo-language-server/lib/project/base.js:25:43)
    at new GraphQLClientProject (~/XXXXX/client/node_modules/apollo-language-server/lib/project/client.js:33:9)
    at Generate.createService (~/XXXXX/client/node_modules/apollo/lib/Command.js:96:28)
    at Generate.init (~/XXXXX/client/node_modules/apollo/lib/Command.js:32:14)
    at <anonymous>
error Command failed with exit code 2.

Still haven't found a way around this. Get the same "no provider was created for config" error.

Should I just be using gql-gen?

I solved this issue by writing a client configuration following directions on this page: https://www.apollographql.com/docs/references/apollo-config.html

This still haven't been resolved. Was on latest version (2.1.9), but had to downgrade to 1.9.2. Any updates?

For those still seeing the issue, can you please provide a reproduction?

i downloaded the latest version of apollo ([email protected]) and included in my package.json and ran below commands and it seems to work...

"schema:download": "apollo service:download --endpoint=http://localhost:4000",
"schema:generate": "apollo client:codegen --localSchemaFile=./schema.json --target=typescript --outputFlat",
"gen:types": "yarn schema:download && yarn schema:generate"

before that, i was trying out different versions of apollo and had encountered the common problems apollo users of earlier versions were facing (eg no provider found, no config file found, fragments operations error etc)

Sorry, I'm late!
Now, It works for me! ([email protected]) Thanks~!

"precodegen": "apollo schema:download --endpoint=http://localhost:4000/graphql",
"codegen": "apollo codegen:generate src/types/api.d.ts --localSchemaFile=schema.json --includes='src/**/!(*.local).ts' --target typescript --outputFlat"
Was this page helpful?
0 / 5 - 0 ratings