apollo-feature-requests icon indicating copy to clipboard operation
apollo-feature-requests copied to clipboard

Subscription: provide a callback to skip saving (and so rendering) new incoming data

Open ruggi99 opened this issue 3 years ago • 2 comments

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

ruggi99 avatar Apr 01 '22 10:04 ruggi99

Any update on this?

ruggi99 avatar Apr 20 '22 12:04 ruggi99

@jpvajda sorry for pinging you. Maybe this feature request was not seen for some reason?

ruggi99 avatar Oct 03 '22 11:10 ruggi99

@jpvajda Is this feature request interesting? Can I try sending a PR?

ruggi99 avatar Jan 05 '23 22:01 ruggi99