You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
QueryManager has become pretty complex and we need to refactor it before the 1.0 release, as described in #464. I'm using this issue to write down what QueryManager's responsibilities should include, some of the issues that currently plague QueryManager and how we can fix them.
Responsibilities
The QueryManager should be responsible for sending queries/mutations to the network interface, receiving the results and dispatching the actions to the store that are needed as part of this transaction, i.e. it should serve as the middleman between the store and the network interface and should expose a way to fetch queries or apply mutations.
Problems + Solutions
fetchQueryOverInterface is way too complicated. We should simplify it by moving the document-changing-functions (e.g. adding fragments, applying query transformations, etc.) to a separate function. The basic logic of fetchQueryOverInterface:
Modify the query document
Diff the query against the store (unless it is a forceFetch)
Send the query over the network interface (write a APOLLO_QUERY_INIT to the store)
Receive the result and incorporate it into the store with a APOLLO_QUERY_RESULT
Each of these should be broken into pieces rather than placed into one monolithic method.
fetchQueryOverInterface should not read from the store - see Don't read from store inside of fetchOverInterface #391. Right now, we do this to check if there are missing fields - this is not necessary and we shouldn't do it.
query should not depend on watchQuery. It creates an observable for pretty much no reason and means that we need the shouldSubscribe hack to make error handling work correctly. Instead, we should just have query call fetchQueryOverInterface directly.
Those seem to be the largest issues to me and once we have fixed those, we should have a pretty readable and robust QueryManager. Feedback appreciated!
The text was updated successfully, but these errors were encountered:
QueryManager
has become pretty complex and we need to refactor it before the 1.0 release, as described in #464. I'm using this issue to write down whatQueryManager
's responsibilities should include, some of the issues that currently plagueQueryManager
and how we can fix them.Responsibilities
The
QueryManager
should be responsible for sending queries/mutations to the network interface, receiving the results and dispatching the actions to the store that are needed as part of this transaction, i.e. it should serve as the middleman between the store and the network interface and should expose a way to fetch queries or apply mutations.Problems + Solutions
fetchQueryOverInterface
is way too complicated. We should simplify it by moving the document-changing-functions (e.g. adding fragments, applying query transformations, etc.) to a separate function. The basic logic offetchQueryOverInterface
:APOLLO_QUERY_INIT
to the store)APOLLO_QUERY_RESULT
Each of these should be broken into pieces rather than placed into one monolithic method.
fetchQueryOverInterface
should not read from the store - see Don't read from store inside of fetchOverInterface #391. Right now, we do this to check if there are missing fields - this is not necessary and we shouldn't do it.query
should not depend onwatchQuery
. It creates an observable for pretty much no reason and means that we need theshouldSubscribe
hack to make error handling work correctly. Instead, we should just havequery
callfetchQueryOverInterface
directly.Those seem to be the largest issues to me and once we have fixed those, we should have a pretty readable and robust QueryManager. Feedback appreciated!
The text was updated successfully, but these errors were encountered: