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
getGraphQLClient
to 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
fetchPolicy
was cache-first. -
client.watchQuery
now uses cache-and-network policy. -
client.query
uses network-only policy. - It's possible to use custom
fetchPolicy
in places where it makes sense through query options.
- The default