-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
relayStyleConnection: Cannot read property 'edges' of undefined in all versions >= v3.3.0 #7822
Comments
@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 It's very strange to me that |
Of course! Thanks for creating an awesome library, sorry I couldn't come up with a proper reproduction! We use type policies for mutations, connections, and subscriptions (none of the subscriptions interact with the connections that have this issue), no other query fields, and no use of |
We are seeing this too whenever we have a nullable connection that returns null. Presumably when a null connection object is merged, the resulting object should be null too |
I'm seeing this issue and Here's it is for reference (the relevant code is in the first few lines): /**
* The original `relayStylePagination` function assumes that `edges` and `pageInfo` are defined but
* we don't always query these fields from our Relay pagination-compatible fields.
*/
export function relayStylePagination<TNode = Reference>(
keyArgs?: FieldPolicy<any>['keyArgs'],
): RelayFieldPolicy<TNode> {
const { keyArgs: policyKeyArgs, read, merge } = originalRelayStylePagination<TNode>(keyArgs)
return {
keyArgs: policyKeyArgs,
read(existing, options) {
if (existing == null || existing.edges == null || existing.pageInfo == null) return existing
return read?.(existing, options)
},
// @ts-expect-error: The incoming type doesn't match the return type.
merge(existing, incoming, options) {
if (incoming == null) return existing
if (existing == null) return incoming
if (
existing.edges == null ||
existing.pageInfo == null ||
incoming.edges == null ||
incoming.pageInfo == null ||
typeof merge !== 'function'
) {
return options.mergeObjects(existing, incoming)
}
return merge(existing, incoming, options)
},
}
} |
FWIW, we had to make two modifications to make this wrapper ultimately work:
keyArgs(args) {
if (args == null) return []
return Object.keys(args).filter(key => !['first', 'after', 'last', 'before'].includes(key))
}, |
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 |
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:These errors, I think, are related to merging of connections with
relayStyleConnection
type policies.existing
will look fine, something like:And
incoming
will beundefined
(and of course thenincoming.edges
is not defined).How to reproduce the issue:
I cannot get a perfect isolated reproduction here, but I did bisect to a commit:
8172159
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.
The text was updated successfully, but these errors were encountered: