apollographql / apollographql/fullstack-tutorial
Uncaught (in promise) Error: GraphQL error: Cannot read property 'id' of null
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 808
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the reproduction steps for a new user and inspect src/datasources/user.js around line 35, where this.context.user.id is accessed. Trace how the guest user is cached during Book All, then verify that the flow no longer raises the reported GraphQL error for users without an email.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, javascript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100