Add empty query detection and skipping
Fixes https://github.com/facebook/relay/issues/5126
Summary
Some queries, when invoked with a set of variables are conceptually "empty". Meaning we can prove before sending them to the server that they will fetch zero fields. Some examples include:
- A query where all top level fields have been skipped via
@skip. - All fields are either Relay resolvers with no server data in their rootFragment, or are client schema extensions
When using a fetch policy like store-or-network we're able to avoid fetching these fields since we find that all server fields can be fulfilled from the cache. However, even when a fetch policy tells us we MUST go to the network, or we are using an API which is designed to explicitly fetch irrespective of fetch policy, these queries can still be safely skipped.
This PR introduces a new check parallel to DataChecker called EmptyChecker which is light-weight and can be called more aggressively than DataChecker. It's faster to run because it does not look up any data in the store, and exits immediately as soon as it finds any server data. This means its time complexity should be on the order of O(top level fields).