web: add `getGraphQLClient` to the `platformContext`
Created by: valerybugakov
Context
Preparation to land https://github.com/sourcegraph/sourcegraph/pull/23351. To leverage Apollo-Client cache in different parts of the app, we need to make it available everywhere without global imports. Similar to distributing the requestGraphql function, we can now access getGraphQLClient from the platformContext.
Changes
- Added
getGraphQLClientto theplatformContext. - Added separate methods to initialize Apollo Client for the web app and the browser extension.
- Apollo Client instance is created asynchronously to restore persistent cache in an async manner in the follow-up PR.
- The delay for async client init is negligible and doesn't affect the perceived performance.
- Updated default fetch policies for Apollo Client to avoid always serving stale cached data:
- The default
fetchPolicywas cache-first. -
client.watchQuerynow uses cache-and-network policy. -
client.queryuses network-only policy. - It's possible to use custom
fetchPolicyin places where it makes sense through query options.
- The default