Skip to content

Commit

Permalink
Make private fields protected in QueryManager (#11013)
Browse files Browse the repository at this point in the history
* chore: create PR for snapshot test

* chore: make QueryManager private fields protected

* chore: add changeset

* Revert "chore: make QueryManager private fields protected"

This reverts commit e0639d3.

* chore: add code comments

* chore: update changeset text

---------

Co-authored-by: Lenz Weber-Tronic <lorenz.weber-tronic@apollographql.com>
  • Loading branch information
alessbell and phryneas authored Jul 5, 2023
1 parent 6a4da90 commit 5ed2cfd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-tools-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@apollo/client': patch
---

Make private fields `inFlightLinkObservables` and `fetchCancelFns` protected in QueryManager in order to make types available in [`@apollo/experimental-nextjs-app-support`](https://www.npmjs.com/package/@apollo/experimental-nextjs-app-support) package when extending the `ApolloClient` class.
18 changes: 11 additions & 7 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ export class QueryManager<TStore> {

// Maps from queryId strings to Promise rejection functions for
// currently active queries and fetches.
private fetchCancelFns = new Map<string, (error: any) => any>();
// Use protected instead of private field so
// @apollo/experimental-nextjs-app-support can access type info.
protected fetchCancelFns = new Map<string, (error: any) => any>();

constructor({
cache,
Expand All @@ -144,7 +146,7 @@ export class QueryManager<TStore> {
assumeImmutableResults?: boolean;
}) {
const defaultDocumentTransform = new DocumentTransform(
(document) => this.cache.transformDocument(document),
(document) => this.cache.transformDocument(document),
// Allow the apollo cache to manage its own transform caches
{ cache: false }
);
Expand All @@ -161,8 +163,8 @@ export class QueryManager<TStore> {
? defaultDocumentTransform
.concat(documentTransform)
// The custom document transform may add new fragment spreads or new
// field selections, so we want to give the cache a chance to run
// again. For example, the InMemoryCache adds __typename to field
// field selections, so we want to give the cache a chance to run
// again. For example, the InMemoryCache adds __typename to field
// selections and fragments from the fragment registry.
.concat(defaultDocumentTransform)
: defaultDocumentTransform
Expand Down Expand Up @@ -695,7 +697,7 @@ export class QueryManager<TStore> {
const query = this.transform(options.query);

// assign variable default values if supplied
// NOTE: We don't modify options.query here with the transformed query to
// NOTE: We don't modify options.query here with the transformed query to
// ensure observable.options.query is set to the raw untransformed query.
options = {
...options,
Expand All @@ -719,7 +721,7 @@ export class QueryManager<TStore> {

this.queries.set(observable.queryId, queryInfo);

// We give queryInfo the transformed query to ensure the first cache diff
// We give queryInfo the transformed query to ensure the first cache diff
// uses the transformed query instead of the raw query
queryInfo.init({
document: query,
Expand Down Expand Up @@ -1027,7 +1029,9 @@ export class QueryManager<TStore> {
return this.localState;
}

private inFlightLinkObservables = new Map<
// Use protected instead of private field so
// @apollo/experimental-nextjs-app-support can access type info.
protected inFlightLinkObservables = new Map<
string,
Map<string, Observable<FetchResult>>
>();
Expand Down

0 comments on commit 5ed2cfd

Please sign in to comment.