Skip to content

Commit af90924

Browse files
authored
export ApolloClient options type (#503)
* export ApolloClient options type * changeset
1 parent 547a3f9 commit af90924

File tree

5 files changed

+144
-9
lines changed

5 files changed

+144
-9
lines changed

.changeset/fifty-tomatoes-collect.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@apollo/client-react-streaming": patch
3+
"@apollo/client-integration-nextjs": patch
4+
---
5+
6+
Export modified `Options` type for `ApolloClient`.

packages/client-react-streaming/src/DataTransportAbstraction/WrappedApolloClient.tsx

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,43 @@ type SimulatedQueryInfo = {
4040
controller: ReadableStreamDefaultController<ReadableStreamLinkEvent>;
4141
options: OrigApolloClient.WatchQueryOptions<any, OperationVariables>;
4242
};
43-
44-
interface WrappedApolloClientOptions
45-
extends Omit<
46-
OrigApolloClient.Options,
47-
"cache" | "ssrMode" | "ssrForceFetchDelay"
48-
> {
49-
cache: InMemoryCache;
43+
/** @public */
44+
export declare namespace ApolloClient {
45+
/** @public */
46+
export interface Options
47+
extends Omit<
48+
OrigApolloClient.Options,
49+
"cache" | "ssrMode" | "ssrForceFetchDelay"
50+
> {
51+
cache: InMemoryCache;
52+
}
53+
/*
54+
We can currently not re-export these types from the upstream ApolloClient implementation because the build
55+
tooling doesn't support that:
56+
> DTS Build error
57+
> Error: namespace child (hoisting) not supported yet
58+
59+
We could re-export them by defining them as new types that reference the originals, but that would require us
60+
to keep generics in sync and would either erase the docblocks or require us to duplicate them
61+
(and they would go out of sync).
62+
If you need any of the other types, please use the `ApolloClient` namespace exported from `@apollo/client` directly.
63+
*/
64+
// export import DefaultOptions = OrigApolloClient.DefaultOptions;
65+
// export import DevtoolsOptions = OrigApolloClient.DevtoolsOptions;
66+
// export import MutateOptions = OrigApolloClient.MutateOptions;
67+
// export import MutateResult = OrigApolloClient.MutateResult;
68+
// export import QueryOptions = OrigApolloClient.QueryOptions;
69+
// export import QueryResult = OrigApolloClient.QueryResult;
70+
// export import RefetchQueriesOptions = OrigApolloClient.RefetchQueriesOptions;
71+
// export import RefetchQueriesResult = OrigApolloClient.RefetchQueriesResult;
72+
// export import SubscribeOptions = OrigApolloClient.SubscribeOptions;
73+
// export import SubscribeResult = OrigApolloClient.SubscribeResult;
74+
// export import WatchFragmentOptions = OrigApolloClient.WatchFragmentOptions;
75+
// export import WatchFragmentResult = OrigApolloClient.WatchFragmentResult;
76+
// export import WatchQueryOptions = OrigApolloClient.WatchQueryOptions;
77+
// export import ReadQueryOptions = OrigApolloClient.ReadQueryOptions;
78+
// export import WriteQueryOptions = OrigApolloClient.WriteQueryOptions;
79+
// export import WriteFragmentOptions = OrigApolloClient.WriteFragmentOptions;
5080
}
5181

5282
const wrappers = Symbol.for("apollo.hook.wrappers");
@@ -60,7 +90,7 @@ class ApolloClientBase extends OrigApolloClient {
6090

6191
[sourceSymbol]: string;
6292

63-
constructor(options: WrappedApolloClientOptions) {
93+
constructor(options: ApolloClient.Options) {
6494
const warnings: string[] = [];
6595
if ("ssrMode" in options) {
6696
delete options.ssrMode;
@@ -111,7 +141,7 @@ class ApolloClientBase extends OrigApolloClient {
111141
}
112142

113143
class ApolloClientClientBaseImpl extends ApolloClientBase {
114-
constructor(options: WrappedApolloClientOptions) {
144+
constructor(options: ApolloClient.Options) {
115145
super(options);
116146
this.onQueryStarted = this.onQueryStarted.bind(this);
117147

packages/nextjs/src/index.shared.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,39 @@ import {
1010
InMemoryCache as UpstreamInMemoryCache,
1111
} from "@apollo/client-react-streaming";
1212

13+
/** @public */
14+
export declare namespace ApolloClient {
15+
/** @public */
16+
export interface Options extends UpstreamApolloClient.Options {}
17+
/*
18+
We can currently not re-export these types from the upstream ApolloClient implementation because the build
19+
tooling doesn't support that:
20+
> DTS Build error
21+
> Error: namespace child (hoisting) not supported yet
22+
23+
We could re-export them by defining them as new types that reference the originals, but that would require us
24+
to keep generics in sync and would either erase the docblocks or require us to duplicate them
25+
(and they would go out of sync).
26+
If you need any of the other types, please use the `ApolloClient` namespace exported from `@apollo/client` directly.
27+
*/
28+
// export import DefaultOptions = UpstreamApolloClient.DefaultOptions;
29+
// export import DevtoolsOptions = UpstreamApolloClient.DevtoolsOptions;
30+
// export import MutateOptions = UpstreamApolloClient.MutateOptions;
31+
// export import MutateResult = UpstreamApolloClient.MutateResult;
32+
// export import QueryOptions = UpstreamApolloClient.QueryOptions;
33+
// export import QueryResult = UpstreamApolloClient.QueryResult;
34+
// export import RefetchQueriesOptions = UpstreamApolloClient.RefetchQueriesOptions;
35+
// export import RefetchQueriesResult = UpstreamApolloClient.RefetchQueriesResult;
36+
// export import SubscribeOptions = UpstreamApolloClient.SubscribeOptions;
37+
// export import SubscribeResult = UpstreamApolloClient.SubscribeResult;
38+
// export import WatchFragmentOptions = UpstreamApolloClient.WatchFragmentOptions;
39+
// export import WatchFragmentResult = UpstreamApolloClient.WatchFragmentResult;
40+
// export import WatchQueryOptions = UpstreamApolloClient.WatchQueryOptions;
41+
// export import ReadQueryOptions = UpstreamApolloClient.ReadQueryOptions;
42+
// export import WriteQueryOptions = UpstreamApolloClient.WriteQueryOptions;
43+
// export import WriteFragmentOptions = UpstreamApolloClient.WriteFragmentOptions;
44+
}
45+
1346
/**
1447
* A version of `ApolloClient` to be used with streaming SSR or in React Server Components.
1548
*

packages/react-router/src/ApolloClient.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,39 @@ function getQueryManager(client: _ApolloClient): InternalTypes.QueryManager & {
1616
return client["queryManager"];
1717
}
1818

19+
/** @public */
20+
export declare namespace ApolloClient {
21+
/** @public */
22+
export interface Options extends _ApolloClient.Options {}
23+
/*
24+
We can currently not re-export these types from the upstream ApolloClient implementation because the build
25+
tooling doesn't support that:
26+
> DTS Build error
27+
> Error: namespace child (hoisting) not supported yet
28+
29+
We could re-export them by defining them as new types that reference the originals, but that would require us
30+
to keep generics in sync and would either erase the docblocks or require us to duplicate them
31+
(and they would go out of sync).
32+
If you need any of the other types, please use the `ApolloClient` namespace exported from `@apollo/client` directly.
33+
*/
34+
// export import DefaultOptions = _ApolloClient.DefaultOptions;
35+
// export import DevtoolsOptions = _ApolloClient.DevtoolsOptions;
36+
// export import MutateOptions = _ApolloClient.MutateOptions;
37+
// export import MutateResult = _ApolloClient.MutateResult;
38+
// export import QueryOptions = _ApolloClient.QueryOptions;
39+
// export import QueryResult = _ApolloClient.QueryResult;
40+
// export import RefetchQueriesOptions = _ApolloClient.RefetchQueriesOptions;
41+
// export import RefetchQueriesResult = _ApolloClient.RefetchQueriesResult;
42+
// export import SubscribeOptions = _ApolloClient.SubscribeOptions;
43+
// export import SubscribeResult = _ApolloClient.SubscribeResult;
44+
// export import WatchFragmentOptions = _ApolloClient.WatchFragmentOptions;
45+
// export import WatchFragmentResult = _ApolloClient.WatchFragmentResult;
46+
// export import WatchQueryOptions = _ApolloClient.WatchQueryOptions;
47+
// export import ReadQueryOptions = _ApolloClient.ReadQueryOptions;
48+
// export import WriteQueryOptions = _ApolloClient.WriteQueryOptions;
49+
// export import WriteFragmentOptions = _ApolloClient.WriteFragmentOptions;
50+
}
51+
1952
/** @public */
2053
export class ApolloClient extends _ApolloClient {
2154
constructor(options: ConstructorParameters<typeof _ApolloClient>[0]) {

packages/tanstack-start/src/index.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,39 @@ import {
66
} from "@apollo/client-react-streaming";
77
import { bundle } from "./bundleInfo.js";
88

9+
/** @public */
10+
export declare namespace ApolloClient {
11+
/** @public */
12+
export interface Options extends UpstreamApolloClient.Options {}
13+
/*
14+
We can currently not re-export these types from the upstream ApolloClient implementation because the build
15+
tooling doesn't support that:
16+
> DTS Build error
17+
> Error: namespace child (hoisting) not supported yet
18+
19+
We could re-export them by defining them as new types that reference the originals, but that would require us
20+
to keep generics in sync and would either erase the docblocks or require us to duplicate them
21+
(and they would go out of sync).
22+
If you need any of the other types, please use the `ApolloClient` namespace exported from `@apollo/client` directly.
23+
*/
24+
// export import DefaultOptions = UpstreamApolloClient.DefaultOptions;
25+
// export import DevtoolsOptions = UpstreamApolloClient.DevtoolsOptions;
26+
// export import MutateOptions = UpstreamApolloClient.MutateOptions;
27+
// export import MutateResult = UpstreamApolloClient.MutateResult;
28+
// export import QueryOptions = UpstreamApolloClient.QueryOptions;
29+
// export import QueryResult = UpstreamApolloClient.QueryResult;
30+
// export import RefetchQueriesOptions = UpstreamApolloClient.RefetchQueriesOptions;
31+
// export import RefetchQueriesResult = UpstreamApolloClient.RefetchQueriesResult;
32+
// export import SubscribeOptions = UpstreamApolloClient.SubscribeOptions;
33+
// export import SubscribeResult = UpstreamApolloClient.SubscribeResult;
34+
// export import WatchFragmentOptions = UpstreamApolloClient.WatchFragmentOptions;
35+
// export import WatchFragmentResult = UpstreamApolloClient.WatchFragmentResult;
36+
// export import WatchQueryOptions = UpstreamApolloClient.WatchQueryOptions;
37+
// export import ReadQueryOptions = UpstreamApolloClient.ReadQueryOptions;
38+
// export import WriteQueryOptions = UpstreamApolloClient.WriteQueryOptions;
39+
// export import WriteFragmentOptions = UpstreamApolloClient.WriteFragmentOptions;
40+
}
41+
942
/**
1043
* A version of `ApolloClient` to be used with TanStack Start.
1144
*

0 commit comments

Comments
 (0)