Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apollo codegen:generate did't work. TypeError: Cannot read property 'name' of undefined #678

Closed
kanziw opened this issue Nov 9, 2018 · 13 comments
Assignees

Comments

@kanziw
Copy link

kanziw commented Nov 9, 2018

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!

@ghost ghost added the blocking label Nov 9, 2018
@kanziw
Copy link
Author

kanziw commented Nov 9, 2018

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"
  }

@amc-david
Copy link

Having the exact same issue.

@lukepighetti
Copy link

Also running into this and unsure how to proceed.

@kanziw
Copy link
Author

kanziw commented Nov 9, 2018

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

@divjose
Copy link

divjose commented Nov 9, 2018

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!

@martijnwalraven
Copy link
Contributor

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

@kanziw
Copy link
Author

kanziw commented Nov 12, 2018

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.

@lukepighetti
Copy link

lukepighetti commented Nov 14, 2018

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?

@0xcaff
Copy link
Contributor

0xcaff commented Dec 20, 2018

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

@Martinnord
Copy link

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

@trevor-scheer
Copy link
Member

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

@myhendry
Copy link

myhendry commented Feb 10, 2019

i downloaded the latest version of apollo (apollo@2.4.4) 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)

@kanziw
Copy link
Author

kanziw commented Mar 1, 2019

Sorry, I'm late!
Now, It works for me! (apollo@2.5.3) 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"

@kanziw kanziw closed this as completed Mar 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants