Skip to content
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

Check for nullable result value to avoid errors on unsubscription #4114

Merged
merged 3 commits into from Jul 19, 2022

Conversation

Maaarcocr
Copy link
Contributor

Why

Currently when I run unsubscribe inside an update method for a subscription class (in ruby) this causes the front-end to fails, because the server sends a new message to the front end that looks like:

{
  more: false
}

Now if you try to result payload.result.data this will error out, as result is undefined and you cannot read .data of undefined.

How I fixed it

By using conditional access to said properties, we can safely read data and errors while not trying to read some properties when result is undefined

@@ -46,7 +46,7 @@ class ActionCableLink extends ApolloLink {
)
},
received: function(payload) {
if (payload.result.data || payload.result.errors) {
if (payload?.result?.data || payload?.result?.errors) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, maybe this should have been if (payload.result), do you think that would work in your case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmosolgo could you run the CI and could we merge this if it's good?

@Maaarcocr
Copy link
Contributor Author

@rmosolgo the test suite is failing because the previous behaviour of not calling the observer when data is null like in:

{
  result: {
    data: null
  },
  more: true
}

has not been kept if we just check result.

Do you want me to change the tests or should I go back to my original implementation where I was doing: payload.result?.data

@rmosolgo
Copy link
Owner

Sorry for the slow merge on this, and thanks for this fix!

@rmosolgo rmosolgo merged commit c7698d0 into rmosolgo:master Jul 19, 2022
@rmosolgo
Copy link
Owner

Released in 1.11.1 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants