fix(gatsby): fix an infinite loop in node child collection (#17078)
fix(gatsby): fix an infinite loop in node child collection (#17078)

* fix: fix an infinite loop in node child collection

* Flip the traversal for speed gains

* After using the cache a lot, it's possible for getNode to return undefined

gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby