问题
I'm trying to remove some nodes from a ast of graphql using the visit function.
Just as the doc says, there are two event I can hook into
- enter
- leave
I don't know when to use enter and when to use leave, what's the deference between them? How can I tell which one to use?
回答1:
The main difference is that enter() allows you to skip the subtree if you don't care about it.
There is a section on this page https://graphql.org/graphql-js/language/#visitor that describes the return values permitted by enter() and leave().
The other reason to use leave() is that if you modified the subtree, you can then look at the modified subtree since it has been processed.
来源:https://stackoverflow.com/questions/65167082/when-to-use-enter-leave-with-visit-function-of-graphql