-
Notifications
You must be signed in to change notification settings - Fork 132
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
withFilter's filterFn is called with a null payload #132
Comments
I would like to point out that the last object sent by an async iterator is normally |
Fix Issue #81 Infinite loop after last unsubscribe in withFilter function
This is tricky since the JS specification for iterators allows a value to be included even when done == true. From iterator protocol |
Not so tricky : currently, the filter is called with an undefined value. This is a bug. The fix could be adapted to test for an undefined value, but the best is to make sure not to use the ambiguity of the protocol. What if the data's last element is an undefined value, how would you know if there is a data or not? |
Okay .. maybe one could test if the key |
I will add another commit to take into account the information you gave and handle the special case you mentioned. |
I suspect that the root cause is completely different. https://github.com/apollographql/graphql-subscriptions/blob/master/src/with-filter.ts#L13 we are getting |
The filterFn is no longer called after there is no more items to iterate on.
I reviewed the code and it LGTM. Rebased and merged. |
Okay, so I was wrong. graphql-subscriptions/src/with-filter.ts Line 14 in 5884380
Promise.all actually just silently ignores non-promise values in the iterable argument it supplies.
Still - I believe the fix is correct - the old version of the code unconditionally calls the
It's not actually clear to me that it makes sense to apply the @NeoPhi Thanks for catching this - what do you think? |
In looking at how the output of this consumed https://github.com/graphql/graphql-js/blob/master/src/subscription/mapAsyncIterator.js#L35 it doesn't look like the calling code considers what happens if a value is set when done is set. Given that the change to check and quick bail when done is set makes sense, even if not 100% accounting for how the JS spec is written. |
withFilter()
'sfilterFn
is called with a null payload when it should not even be called.I strongly suspect (because I took a look at its source code) that it is called when the async iterator is returning an object that says that there is no more values.
That's wrong, the filter function should not be called when there is no more value in the iterator.
payload.done === true
should be tested before callingfilterFn
.The text was updated successfully, but these errors were encountered: