graphiql icon indicating copy to clipboard operation
graphiql copied to clipboard

Cannot use graphiql at all when having this error: 'length' of undefined at getToken

Open codTango opened this issue 9 years ago • 10 comments

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)

codTango avatar Mar 02 '17 15:03 codTango

I'm also getting this, and can't find anyway to resolve it.

joewoodhouse avatar Mar 03 '17 09:03 joewoodhouse

@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.

asiandrummer avatar Mar 06 '17 20:03 asiandrummer

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 avatar Mar 09 '17 12:03 gesposito

@gesposito wondering what you mean solve the issue? it's been fixed temporarily or permanently?

codTango avatar Mar 09 '17 17:03 codTango

@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

woahitsraj avatar Mar 11 '17 18:03 woahitsraj

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.

maxrbaldwin avatar Mar 21 '17 20:03 maxrbaldwin

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?

wincent avatar Mar 21 '17 23:03 wincent

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.)

alankent avatar May 26 '17 05:05 alankent

(Just for the record I don't care about this issue any more because I found the GraphIQL apps for Chrome. Click, installed, done.)

alankent avatar Jun 09 '17 00:06 alankent

++ 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. (/Users/bohaishuo/.nvm/versions/node/v7.0.0/lib/node_modules/apollo-codegen/lib/cli.js:197:5) at Module._compile (module.js:573:32) at Object.Module._extensions..js (module.js:582:10) at Module.load (module.js:490:32) at tryModuleLoad (module.js:449:12) at Function.Module._load (module.js:441:3) Command /bin/sh failed with exit code 1

I also have this problem, can you tell me the detailed solution?

Davidxiaoshuo avatar Jun 06 '18 08:06 Davidxiaoshuo