Cannot use graphiql at all when having this error: 'length' of undefined at getToken
I'm actually not sure if I should post this here or for express-graphql as I'm using express-graphql, but since this error is coming from graphiql.min.js, I'm posting this issue here.
Situation
Occasionally, the graphiql will get the below error in console, and then Documentation Explorer will keep spinning and graphiql will become unusable. Most cases I found command + c/v to copy and paste in the QUERY VARIABLES panel will cause the problem. After it happens, I won't be able to use graphiql for a while, doesn't work even hard refresh the page. Then it will just work again after a long time.
Uncaught TypeError: Cannot read property 'length' of undefined
at getToken (graphiql.min.js:4)
at Object.token (graphiql.min.js:4)
at nt (graphiql.min.js:7)
at lt (graphiql.min.js:7)
at Qe (graphiql.min.js:7)
at Je (graphiql.min.js:7)
at ht (graphiql.min.js:7)
at At (graphiql.min.js:7)
at Pt (graphiql.min.js:7)
at Tn (graphiql.min.js:8)
I'm also getting this, and can't find anyway to resolve it.
@codTango @joewoodhouse I'm suspecting that error is from our online parser (codemirror-graphql). As a solution, I'm going to work on pushing a flow-typed version of our online parser for GraphiQL to use. Meanwhile, to work around this, clearing your browser cache (or deleting the local (localstorage) content) should make GraphiQL usable again.
Thanks for the report you guys! I'm going to keep this open to track the progress.
I'm not sure why, but invoking localStorage.clear() didn't solve this issue for me.
I solved this by disabling (graphiql: false), clearing the storage, and enabling GraphiQL again from express-graphql.
@gesposito wondering what you mean solve the issue? it's been fixed temporarily or permanently?
@gesposito Thanks man this worked for me. For more clarity, find this line in your code
app.use('/graphql', expressGraphQL({
schema,
graphiql: true
}));
and change it to
app.use('/graphql', expressGraphQL({
schema,
graphiql: false
}));
Then start and stop the server and go to the console and run
localStorage.clear()
Then change the flag back to true and restart the server
app.use('/graphql', expressGraphQL({
schema,
graphiql: true
}));
Should fix the issue
I ran into this same issue just now. This started happening only when I triggered the "Documentation Explorer" in Graphiql. Now, I can't close the "Documentation Explorer" panel and the loading icon keeps spinning. My error is Uncaught TypeError: Cannot read property 'length' of undefined at getToken.
Please note that my Graphql route works fine. It is only Graphiql that isn't working.
We fixed an issue like this in https://github.com/graphql/graphiql/commit/eb9f171d1325819bc3ce852fcdbb17784ffc460a which was included in v0.9.2. What version of GraphiQL are you using?
I am having this trouble as well. It appears express-graphiql is still 1.0.0 and so I am getting 0.9.1. (I am a nodejs newbie, but it appears express-graphiql has not been published for a while, so its not picking up the latest code.)
(Just for the record I don't care about this issue any more because I found the GraphIQL apps for Chrome. Click, installed, done.)
++ exec 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] (/Users/bohaishuo/.nvm/versions/node/v7.0.0/lib/node_modules/apollo-codegen/src/cli.js:186:16)
at Object.runCommand (/Users/bohaishuo/.nvm/versions/node/v7.0.0/lib/node_modules/apollo-codegen/node_modules/yargs/lib/command.js:235:44)
at Object.parseArgs [as _parseArgs] (/Users/bohaishuo/.nvm/versions/node/v7.0.0/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:1013:30)
at Object.get [as argv] (/Users/bohaishuo/.nvm/versions/node/v7.0.0/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:957:21)
at Object.
I also have this problem, can you tell me the detailed solution?