question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught (in promise) Error: GraphQL error: Cannot read property 'id' of null

See original GitHub issue

Steps to reproduce:

  1. Login as a new user (hasn’t entered their email yet)
  2. Select a trip from the home page
  3. Add trip to cart
  4. Go to cart
  5. Click Book All

It will explode with: Uncaught (in promise) Error: GraphQL error: Cannot read property ‘id’ of null.

Looking at the error more closely reveals that we are caching the guest user somewhere. The error comes back from

// src/datasources/user.js:35
const userId = this.context.user.id;
if (!userId) return;

This means the user context is null

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

9reactions
philohelpcommented, Feb 26, 2019

Same error here. Unable to execute the last part of the tutorial - on the server part. This is very disturbing when you want to learn a new piece of knowledge and you find yourself trying to solve a bug in a technology that by definition you don’t master yet.

1reaction
gdesjonquerescommented, Jan 1, 2020

Surprisingly this issue is still opened. According to Apollo Client own documentation authentication token should be handled this way: https://stackoverflow.com/questions/58556687/react-apollo-how-to-set-authorization-header-when-user-logs-in

(See first solution by Abderrahim Soubai Elidrissi)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix "Cannot read property 'id' of null" error in javascript?
It looks like the user is not found. Try changing async bookTrips({ launchIds }) { const userId = this.context.user.id;. to
Read more >
Cannot read properties of undefined (reading 'id') - TrackJS
In this case, our code expects to have an object with a id property, but that object was not present.
Read more >
How to Avoid Getting 'Cannot read property of undefined' in ...
This error occurs when you try to read or access a property on an object that is undefined . Another common case that...
Read more >
TypeError: cannot use 'in' operator to search for 'x' in 'y'
Make sure the object you are inspecting isn't actually null or undefined . const foo = null; "bar" in foo; // ...
Read more >
TypeError: Cannot read property 'then' of undefined. Getting ...
[Solved]-TypeError: Cannot read property 'then' of undefined. Getting this error when I am trying to run updatefirst function-mongodb.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found