useOnResolve
incorrectly calls onResolve
multiple times
#2222
Labels
kind/bug
Something isn't working
stage/0-issue-prerequisites
Needs more information before we can start working on it
Summary
If you have:
useOnResolve
onSchemaChange
is triggered more than oncethen
field.resolve
will be wrapped multiple times andonResolve
will be triggered multiple times.Detail
The number of redundant calls will be proportional to the number of
useOnResolve
plugins, and the number of timesonSchemaChange
is called.This happens because the
hasWrappedResolve
symbol is private to a single plugin instance.Reproduction
Consider the following scenario:
useOnResolve
, Plugin A and Plugin BonSchemaChange
fires the first timefield.resolve
So far, so good, each plugin will still behave as expected(
onResolve
is still only called once for each plugin when a resolver is invoked), however:onSchemaChange
is fired a second time.Now when a resolver is called
onResolve
ends up getting called twice per plugin.Suggested solution
Symbol('parentResolver')
, this symbol must be a singleton, not private to a single plugin instance.field.resolve
,field[parentResolver]
should be set to the original resolver.hasWrappedResolveSymbol
set, theparentResolver
should be recursively checked to ensure that the resolver has not already been wrapped.Side-note, the
parentResolver
symbol should probably be publicly exported, so that other code that may also be wrapping resolvers, can use it.The text was updated successfully, but these errors were encountered: