Closed morrys closed 8 months ago
@sibelius do you know what are the use cases when next is called only once? 💯
@Lalitha-Iyer I'm considering modifying the onNext function in QueryFetcher like this:
const onNext = (
_o: OperationDescriptor,
snapshot: Snapshot,
response: GraphQLResponse,
): void => {
if (!this.snapshot) {
this.snapshot = snapshot;
this.subscribe(snapshot);
this.resolveResult();
const responses = Array.isArray(response) ? response : [response];
const isFinal = responses.some((x) => x != null && x.extensions?.is_final === true);
if (fetchHasReturned && !isFinal) {
this.forceUpdate();
}
}
};
So anyone in the relay network can add that information to the response and change the behavior of useQuery.
I would prefer an option over isFinal, just because it's would be easier to build an abstraction on top. Eventually, we could move to the model of automatically figuring out when to skip the extra re-render, and then this option would be used as an escape hatch to force an extra re-render in case unknown bugs come up.
released with version 8.0.0
the request comes from this comment:
It would be interesting to investigate the possibility of identifying queries that call next only once during fetch.
This would allow us to implement automation, such as for polling, and avoid introducing a new parameter to be passed to useQuery and useLazyLoadQuery.