joelgriffith / navalia

A bullet-proof, fast, and reliable headless browser API
https://joelgriffith.github.io/navalia/
GNU General Public License v3.0
957 stars 33 forks source link

GraphQL queries running in parallel and in their own context #30

Closed joelgriffith closed 5 years ago

joelgriffith commented 7 years ago

Really like this idea. Some thoughts I have:

mute commented 7 years ago

Totally agreed with those concerns -- here's my hand wavy explanation of how I think this might be possible, but it's hand wavy because I'm not a GraphQL guru:

1) Parse GraphQL query into an array of Promise chains which resolve to the sequence of actual navalia / chrome API functions. This should result in n Promises where n is the number of leaf nodes in the query. 2) For each of these Promises, spawn a tab up to whatever the maximum specified number of tabs is. 3) Resolve each promise chain in its corresponding tab. 4) Continue until tabs have been spawned / resolved for each leaf node.

So, we shouldn't need to clone tabs, each tab will just execute the same series of steps in parallel up until the query branches.

joelgriffith commented 7 years ago

Ah, that definitely removes some of the challenges related to having branching work as expected. I know this is entirely possible (things like join-monster do this), but would definitely take some meaty work to do so. I'll dig into how to do this, as it's a pretty interesting idea!