Skip to content

Commit d04bdea

Browse files
create branded QueryRef type without exposed properties (#11824)
* create branded `QueryReferenceBase` type * update some test types * changeset * split up into new hierarchy starting from QueryRef type * add export * add some type assignability tests * update doc references * toPromise return type * adjust changeset * stabilize flaky test * Update .changeset/late-planets-argue.md Co-authored-by: Jerel Miller <[email protected]> * types in tests * adjust notes * fix integration test TS --------- Co-authored-by: Jerel Miller <[email protected]>
1 parent bdc83d8 commit d04bdea

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

src/testing/matchers/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
DocumentNode,
44
OperationVariables,
55
} from "../../core/index.js";
6-
import type { QueryReference } from "../../react/index.js";
6+
import type { QueryRef } from "../../react/index.js";
77
import {
88
NextRenderOptions,
99
Profiler,
@@ -15,8 +15,8 @@ interface ApolloCustomMatchers<R = void, T = {}> {
1515
/**
1616
* Used to determine if a queryRef has been disposed.
1717
*/
18-
toBeDisposed: T extends QueryReference<any, any> ? () => R
19-
: { error: "matcher needs to be called on a QueryReference" };
18+
toBeDisposed: T extends QueryRef<any, any> ? () => R
19+
: { error: "matcher needs to be called on a QueryRef" };
2020
/**
2121
* Used to determine if two GraphQL query documents are equal to each other by
2222
* comparing their printed values. The document must be parsed by `gql`.

src/testing/matchers/toBeDisposed.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
import type { MatcherFunction } from "expect";
2-
import type { QueryReference } from "../../react/internal/index.js";
2+
import type { QueryRef } from "../../react/internal/index.js";
33
import {
4-
InternalQueryReference,
4+
assertWrappedQueryRef,
55
unwrapQueryRef,
66
} from "../../react/internal/index.js";
77

8-
function isQueryRef(queryRef: unknown): queryRef is QueryReference {
9-
try {
10-
return unwrapQueryRef(queryRef as any) instanceof InternalQueryReference;
11-
} catch (e) {
12-
return false;
13-
}
14-
}
15-
16-
export const toBeDisposed: MatcherFunction<[]> = function (queryRef) {
8+
export const toBeDisposed: MatcherFunction<[]> = function (_queryRef) {
179
const hint = this.utils.matcherHint("toBeDisposed", "queryRef", "", {
1810
isNot: this.isNot,
1911
});
2012

21-
if (!isQueryRef(queryRef)) {
22-
throw new Error(`\n${hint}\n\nmust be called with a valid QueryReference`);
23-
}
13+
const queryRef = _queryRef as QueryRef;
14+
assertWrappedQueryRef(queryRef);
2415

2516
const pass = unwrapQueryRef(queryRef).disposed;
2617

0 commit comments

Comments
 (0)