apollo-feature-requests
apollo-feature-requests copied to clipboard
Subscription: provide a callback to skip saving (and so rendering) new incoming data
Hi all,
I'd like to have a function in the useSubscription hook options that returns a boolean indicating if incoming data must be saved and the page re-rendered or data must be discarded.
function canSaveNewData(data) {
// custom logic here
return true;
}
function MYComponent() {
const { data } = useSubscription(MY_SUB, { onNewData: canSaveNewData })
return <div>{data}</div>;
}
So with the function canSaveNewData I can skip incoming data.
I need it because the back-end I'm using, can, sometimes, push me wrong data that it's not coerent and I want to not save this data.
I don't think it'll change any behaviour, simply it'll add a new function to the options of the hook. If the function is not provided than incoming data is always saved.
Is it possible to do this thing?
Thanks
EDIT: possible use cases:
- skip some data that is not coerent or out of schema.
- Throttling incoming data, if the rate is too high
Any update on this?
@jpvajda sorry for pinging you. Maybe this feature request was not seen for some reason?
@jpvajda Is this feature request interesting? Can I try sending a PR?