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.

relayStyleConnection: Cannot read property 'edges' of undefined in all versions >= v3.3.0

See original GitHub issue

Intended outcome: After upgrading from 3.2.x to 3.3.x, pages load correctly without error.

Actual outcome: We’ve been stuck on 3.2.x for the last several months due to this error when loading pages that use connections with relayStyleConnection-based type policies:

TypeError: Cannot read property 'edges' of undefined
    at merge (webpack-internal:///./node_modules/@apollo/client/utilities/utilities.cjs.js:704:45)
    at Policies.runMergeFunction (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:1299:20)
    at StoreWriter.applyMerges (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:880:40)
    at eval (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:863:34)
    at Map.forEach (<anonymous>)
    at StoreWriter.applyMerges (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:860:27)
    at StoreWriter.processSelectionSet (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:812:39)
    at StoreWriter.processFieldValue (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:839:21)
    at eval (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:782:47)
    at Set.forEach (<anonymous>)
    at StoreWriter.processSelectionSet (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:767:17)
    at StoreWriter.processFieldValue (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:839:21)
    at eval (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:782:47)
    at Set.forEach (<anonymous>)
    at StoreWriter.processSelectionSet (webpack-internal:///./node_modules/@apollo/client/cache/cache.cjs.js:767:17)

These errors, I think, are related to merging of connections with relayStyleConnection type policies. existing will look fine, something like:

{
  __typename: 'FooConnection',
  edges: [
    {
      __typename: 'FooEdge',
      cursor: 'MzkzNjc2M45DE3ODYw',
      node: [Object]
    }
  ],
  pageInfo: {
    __typename: 'PageInfo',
    startCursor: 'MzkzNjc45DE3ODYw',
    endCursor: 'MzkzADMjI4MjE3Yw',
    hasNextPage: false,
    hasPreviousPage: false
  }
}

And incoming will be undefined (and of course then incoming.edges is not defined).

How to reproduce the issue: I cannot get a perfect isolated reproduction here, but I did bisect to a commit: https://github.com/apollographql/apollo-client/commit/8172159e7033d195b5dd7747ecb54c8b437a0df9

These errors only throw with relayStyleConnection. The point in the code this throws at is: https://github.com/apollographql/apollo-client/blob/main/src/utilities/policies/pagination.ts#L130

Versions Every version after and including 3.3.0-beta.4.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
benjamncommented, Mar 10, 2021

@SirensOfTitan First of all, thanks for surfacing this issue instead of continuing to suffer in silence, and thanks for going to the trouble of bisecting it.

Do you have any other type or field policies defined where the relayStylePagination() policy is used? For example, are there any merge: true configurations for the field that holds this FooConnection object, or any places where you use the mergeObjects helper function in a field merge function?

It’s very strange to me that incoming should ever be undefined, so if we can figure out why that happens, that’s likely to be the/a bug.

0reactions
benjamncommented, Aug 30, 2021

Fix incoming, based on @bubba’s PR #7949 (and incorporating @migueloller’s code above): #8733

@SirensOfTitan Please take a look, and sorry for the wait!

@migueloller I’m optimistic that the {existing,incoming}.{edges,pageInfo} == null checking is not really necessary, since those properties are checked for truthiness before they’re used, but please feel free to comment on #8733 if you think additional changes are needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'allWordpressAcfOptions' of undefined ...
You're expecting data.allWordpressAcfOptions.edges to be an array right? So you need to map over that first.
Read more >
cannot read properties of undefined (reading 'split') mongoose
My node version is 14.16.1, mongoose version is 5.11.1. Stack trace included below : Uncaught TypeError: Cannot read properties of undefined (reading ...
Read more >
Ghost 3.0 Update Q: Install Cannot Read Property 'Type' of ...
Hello, Trying my best to update to Ghost 3.0 but I get the following error ... Message: Cannot read property 'type' of undefined...
Read more >
Migrating from v2 to v3 - Gatsby
You need to update your package.json to use the latest version of Gatsby. ... encounter any of these issues when migrating your project...
Read more >
"Cannot read property 'message' of undefined" error from ...
Description. Since upgrading to v3.2.4, we started seeing occasional fatal errors from `connect`. It seems that a ...
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