Skip to content

Commit

Permalink
remove ensureResult for this PR, add TODO type
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Sep 14, 2023
1 parent a101977 commit f2555fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
19 changes: 4 additions & 15 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { QueryInfo } from "./QueryInfo.js";
import type { MissingFieldError } from "../cache/index.js";
import type { MissingTree } from "../cache/core/types/common.js";
import { equalByQuery } from "./equalByQuery.js";
import type { TODO } from "../utilities/types/TODO.js";

const { assign, hasOwnProperty } = Object;

Expand Down Expand Up @@ -408,7 +409,7 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
}

this.queryInfo.resetLastWrite();
return this.reobserve(reobserveOptions, NetworkStatus.refetch);
return this.reobserve(reobserveOptions, NetworkStatus.refetch) as TODO;
}

public fetchMore<
Expand Down Expand Up @@ -588,7 +589,7 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
public setOptions(
newOptions: Partial<WatchQueryOptions<TVariables, TData>>
): Promise<ApolloQueryResult<TData>> {
return this.reobserve(newOptions);
return this.reobserve(newOptions) as TODO;
}

public silentSetOptions(
Expand Down Expand Up @@ -928,9 +929,7 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
newOptions?: Partial<WatchQueryOptions<TVariables, TData>>,
newNetworkStatus?: NetworkStatus
) {
return this.reobserveAsConcast(newOptions, newNetworkStatus).promise.then(
ensureResult
);
return this.reobserveAsConcast(newOptions, newNetworkStatus).promise;
}

public resubscribeAfterError(
Expand Down Expand Up @@ -1096,13 +1095,3 @@ function skipCacheDataFor(
fetchPolicy === "standby"
);
}

export function ensureResult<TData = any>(
value: ApolloQueryResult<TData> | undefined
): ApolloQueryResult<TData> {
invariant(
value,
"A Concast finished without a result. This in an Apollo Client bug, please file a bug report."
);
return value;
}
14 changes: 4 additions & 10 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ import type {
ErrorPolicy,
MutationFetchPolicy,
} from "./watchQueryOptions.js";
import {
ObservableQuery,
ensureResult,
logMissingFieldErrors,
} from "./ObservableQuery.js";
import { ObservableQuery, logMissingFieldErrors } from "./ObservableQuery.js";
import { NetworkStatus, isNetworkRequestInFlight } from "./networkStatus.js";
import type {
ApolloQueryResult,
Expand All @@ -78,6 +74,7 @@ import {
import type { ApolloErrorOptions } from "../errors/index.js";
import { PROTOCOL_ERRORS_SYMBOL } from "../errors/index.js";
import { print } from "../utilities/index.js";
import type { TODO } from "../utilities/types/TODO.js";

const { hasOwnProperty } = Object.prototype;

Expand Down Expand Up @@ -620,11 +617,8 @@ export class QueryManager<TStore> {
options: WatchQueryOptions<TVars, TData>,
networkStatus?: NetworkStatus
): Promise<ApolloQueryResult<TData>> {
return this.fetchConcastWithInfo(
queryId,
options,
networkStatus
).concast.promise.then(ensureResult);
return this.fetchConcastWithInfo(queryId, options, networkStatus).concast
.promise as TODO;
}

public getQueryStore() {
Expand Down
3 changes: 2 additions & 1 deletion src/react/cache/QueryReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "../../utilities/index.js";
import type { CacheKey } from "./types.js";
import type { useBackgroundQuery, useReadQuery } from "../hooks/index.js";
import type { TODO } from "../../utilities/types/TODO.js";

type Listener<TData> = (promise: Promise<ApolloQueryResult<TData>>) => void;

Expand Down Expand Up @@ -174,7 +175,7 @@ export class InternalQueryReference<TData = unknown> {
currentFetchPolicy === "standby" &&
currentFetchPolicy !== watchQueryOptions.fetchPolicy
) {
this.initiateFetch(this.observable.reobserve(watchQueryOptions));
this.initiateFetch(this.observable.reobserve(watchQueryOptions) as TODO);
} else {
this.observable.silentSetOptions(watchQueryOptions);

Expand Down
2 changes: 2 additions & 0 deletions src/utilities/types/TODO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @internal */
export type TODO = any;

0 comments on commit f2555fa

Please sign in to comment.