When to use enter/leave with `visit` function of `graphql`

回眸只為那壹抹淺笑 提交于 2020-12-15 05:25:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!