Skip to content

Commit 6d3d5ba

Browse files
committed
BREAKING Requires @apollo/client 3.13.1
- Requires `@apollo/client` 3.13.1 - Dropped `SubscriptionResult`, because it added extra maintenance work to keep native types in sync, and it brought no value over using native type. ```diff - import type { SubscriptionResult } from 'apollo-angular'; + import type { FetchResult } from '@apollo/client/core'; ``` - Most methods of `QueryRef` forward types from `@apollo/client`. That should allow always using correct types from whichever `@apollo/client` version is installed without needing to touch `apollo-angular`. - `QueryRef.valueChanges` and `QueryRef.queryId` are readonly, because there is no reason for those to be re-affected.
1 parent 49fc004 commit 6d3d5ba

File tree

8 files changed

+88
-68
lines changed

8 files changed

+88
-68
lines changed

.changeset/khaki-worms-lick.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'apollo-angular': major
3+
---
4+
5+
- Requires `@apollo/client` 3.13.1
6+
- Dropped `SubscriptionResult`, because it added extra maintenance work to
7+
keep native types in sync, and it brought no value over using native
8+
type.
9+
```diff
10+
- import type { SubscriptionResult } from 'apollo-angular';
11+
+ import type { FetchResult } from '@apollo/client/core';
12+
```
13+
- Most methods of `QueryRef` forward types from `@apollo/client`. That
14+
should allow always using correct types from whichever `@apollo/client`
15+
version is installed without needing to touch `apollo-angular`.
16+
- `QueryRef.valueChanges` and `QueryRef.queryId` are readonly, because
17+
there is no reason for those to be re-affected.
18+

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@angular/platform-browser-dynamic": "^18.0.0",
3838
"@angular/platform-server": "^18.0.0",
3939
"@angular/router": "^18.0.0",
40-
"@apollo/client": "^3.10.4",
40+
"@apollo/client": "^3.13.1",
4141
"@babel/core": "^7.24.6",
4242
"@babel/preset-env": "^7.24.6",
4343
"@changesets/changelog-github": "^0.5.0",

packages/apollo-angular/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"peerDependencies": {
3737
"@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0",
38-
"@apollo/client": "^3.10.0",
38+
"@apollo/client": "^3.13.1",
3939
"graphql": "^15.0.0 || ^16.0.0",
4040
"rxjs": "^6.0.0 || ^7.0.0"
4141
},

packages/apollo-angular/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export type {
1515
QueryOptionsAlone,
1616
ResultOf,
1717
SubscriptionOptionsAlone,
18-
SubscriptionResult,
1918
VariablesOf,
2019
WatchQueryOptions,
2120
WatchQueryOptionsAlone,

packages/apollo-angular/src/query-ref.ts

+38-30
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { from, Observable } from 'rxjs';
22
import { NgZone } from '@angular/core';
33
import type {
4-
ApolloError,
54
ApolloQueryResult,
6-
FetchMoreQueryOptions,
75
ObservableQuery,
86
OperationVariables,
97
SubscribeToMoreOptions,
108
TypedDocumentNode,
11-
UpdateQueryOptions,
129
} from '@apollo/client/core';
1310
import { NetworkStatus } from '@apollo/client/core';
1411
import { EmptyObject, WatchQueryOptions } from './types';
@@ -46,14 +43,14 @@ function useInitialLoading<T, V extends OperationVariables>(obsQuery: Observable
4643
export type QueryRefFromDocument<T extends TypedDocumentNode> =
4744
T extends TypedDocumentNode<infer R, infer V> ? QueryRef<R, V & OperationVariables> : never;
4845

49-
export class QueryRef<T, V extends OperationVariables = EmptyObject> {
50-
public valueChanges: Observable<ApolloQueryResult<T>>;
51-
public queryId: ObservableQuery<T, V>['queryId'];
46+
export class QueryRef<TData, TVariables extends OperationVariables = EmptyObject> {
47+
public readonly valueChanges: Observable<ApolloQueryResult<TData>>;
48+
public readonly queryId: ObservableQuery<TData, TVariables>['queryId'];
5249

5350
constructor(
54-
private readonly obsQuery: ObservableQuery<T, V>,
51+
private readonly obsQuery: ObservableQuery<TData, TVariables>,
5552
ngZone: NgZone,
56-
options: WatchQueryOptions<V, T>,
53+
options: WatchQueryOptions<TVariables, TData>,
5754
) {
5855
const wrapped = wrapWithZone(from(fixObservable(this.obsQuery)), ngZone);
5956

@@ -65,69 +62,80 @@ export class QueryRef<T, V extends OperationVariables = EmptyObject> {
6562

6663
// ObservableQuery's methods
6764

68-
public get options() {
65+
public get options(): ObservableQuery<TData, TVariables>['options'] {
6966
return this.obsQuery.options;
7067
}
7168

72-
public get variables() {
69+
public get variables(): ObservableQuery<TData, TVariables>['variables'] {
7370
return this.obsQuery.variables;
7471
}
7572

76-
public result(): Promise<ApolloQueryResult<T>> {
73+
public result(): ReturnType<ObservableQuery<TData, TVariables>['result']> {
7774
return this.obsQuery.result();
7875
}
7976

80-
public getCurrentResult(): ApolloQueryResult<T> {
77+
public getCurrentResult(): ReturnType<ObservableQuery<TData, TVariables>['getCurrentResult']> {
8178
return this.obsQuery.getCurrentResult();
8279
}
8380

84-
public getLastResult(): ApolloQueryResult<T> | undefined {
81+
public getLastResult(): ReturnType<ObservableQuery<TData, TVariables>['getLastResult']> {
8582
return this.obsQuery.getLastResult();
8683
}
8784

88-
public getLastError(): ApolloError | undefined {
85+
public getLastError(): ReturnType<ObservableQuery<TData, TVariables>['getLastError']> {
8986
return this.obsQuery.getLastError();
9087
}
9188

92-
public resetLastResults(): void {
89+
public resetLastResults(): ReturnType<ObservableQuery<TData, TVariables>['resetLastResults']> {
9390
return this.obsQuery.resetLastResults();
9491
}
9592

96-
public refetch(variables?: V): Promise<ApolloQueryResult<T>> {
93+
public refetch(
94+
variables?: Parameters<ObservableQuery<TData, TVariables>['refetch']>[0],
95+
): ReturnType<ObservableQuery<TData, TVariables>['refetch']> {
9796
return this.obsQuery.refetch(variables);
9897
}
9998

100-
public fetchMore<K = V>(
101-
fetchMoreOptions: FetchMoreQueryOptions<K, T>,
102-
): Promise<ApolloQueryResult<T>> {
99+
public fetchMore<TFetchVars extends OperationVariables = TVariables>(
100+
fetchMoreOptions: Parameters<QueryRef<TData, TFetchVars>['obsQuery']['fetchMore']>[0],
101+
): ReturnType<QueryRef<TData, TFetchVars>['obsQuery']['fetchMore']> {
103102
return this.obsQuery.fetchMore(fetchMoreOptions);
104103
}
105104

106-
public subscribeToMore<MT = any, MV = EmptyObject>(
107-
options: SubscribeToMoreOptions<T, MV, MT>,
108-
): () => void {
109-
// XXX: there's a bug in apollo-client typings
110-
// it should not inherit types from ObservableQuery
111-
return this.obsQuery.subscribeToMore(options as any);
105+
public subscribeToMore<
106+
TSubscriptionData = TData,
107+
TSubscriptionVariables extends OperationVariables = TVariables,
108+
>(
109+
options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>,
110+
): ReturnType<ObservableQuery<TData, TVariables>['subscribeToMore']> {
111+
return this.obsQuery.subscribeToMore(options);
112112
}
113113

114-
public updateQuery(mapFn: (previousQueryResult: T, options: UpdateQueryOptions<V>) => T): void {
114+
public updateQuery(
115+
mapFn: Parameters<ObservableQuery<TData, TVariables>['updateQuery']>[0],
116+
): ReturnType<ObservableQuery<TData, TVariables>['updateQuery']> {
115117
return this.obsQuery.updateQuery(mapFn);
116118
}
117119

118-
public stopPolling(): void {
120+
public stopPolling(): ReturnType<ObservableQuery<TData, TVariables>['stopPolling']> {
119121
return this.obsQuery.stopPolling();
120122
}
121123

122-
public startPolling(pollInterval: number): void {
124+
public startPolling(
125+
pollInterval: Parameters<ObservableQuery<TData, TVariables>['startPolling']>[0],
126+
): ReturnType<ObservableQuery<TData, TVariables>['startPolling']> {
123127
return this.obsQuery.startPolling(pollInterval);
124128
}
125129

126-
public setOptions(opts: Partial<WatchQueryOptions<V, T>>) {
130+
public setOptions(
131+
opts: Parameters<ObservableQuery<TData, TVariables>['setOptions']>[0],
132+
): ReturnType<ObservableQuery<TData, TVariables>['setOptions']> {
127133
return this.obsQuery.setOptions(opts);
128134
}
129135

130-
public setVariables(variables: V) {
136+
public setVariables(
137+
variables: Parameters<ObservableQuery<TData, TVariables>['setVariables']>[0],
138+
): ReturnType<ObservableQuery<TData, TVariables>['setVariables']> {
131139
return this.obsQuery.setVariables(variables);
132140
}
133141
}

packages/apollo-angular/src/subscription.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import type { DocumentNode } from 'graphql';
22
import type { Observable } from 'rxjs';
33
import { Injectable } from '@angular/core';
4-
import type { OperationVariables, TypedDocumentNode } from '@apollo/client/core';
4+
import type { FetchResult, OperationVariables, TypedDocumentNode } from '@apollo/client/core';
55
import { Apollo } from './apollo';
6-
import {
7-
EmptyObject,
8-
ExtraSubscriptionOptions,
9-
SubscriptionOptionsAlone,
10-
SubscriptionResult,
11-
} from './types';
6+
import { EmptyObject, ExtraSubscriptionOptions, SubscriptionOptionsAlone } from './types';
127

138
@Injectable()
149
export abstract class Subscription<T = any, V extends OperationVariables = EmptyObject> {
@@ -21,7 +16,7 @@ export abstract class Subscription<T = any, V extends OperationVariables = Empty
2116
variables?: V,
2217
options?: SubscriptionOptionsAlone<V, T>,
2318
extra?: ExtraSubscriptionOptions,
24-
): Observable<SubscriptionResult<T>> {
19+
): Observable<FetchResult<T>> {
2520
return this.apollo.use(this.client).subscribe<T, V>(
2621
{
2722
...options,

packages/apollo-angular/src/types.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { ExecutionResult } from 'graphql';
21
import type {
32
ApolloClientOptions,
43
MutationOptions as CoreMutationOptions,
@@ -69,8 +68,6 @@ export interface MutationOptions<TData = any, TVariables = EmptyObject>
6968
export interface WatchFragmentOptions<TData = any, TVariables = EmptyObject>
7069
extends CoreWatchFragmentOptions<TData, TVariables> {}
7170

72-
export interface SubscriptionResult<TData> extends ExecutionResult<TData> {}
73-
7471
export type NamedOptions = Record<string, ApolloClientOptions<any>>;
7572

7673
export type Flags = {

yarn.lock

+27-24
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@
251251
dependencies:
252252
tslib "^2.3.0"
253253

254-
"@apollo/client@^3.10.4":
255-
version "3.10.8"
256-
resolved "https://registry.yarnpkg.com/@apollo/client/-/client-3.10.8.tgz#96b1548818e45fac752ec2bd318e5466d9ca26b5"
257-
integrity sha512-UaaFEitRrPRWV836wY2L7bd3HRCfbMie1jlYMcmazFAK23MVhz/Uq7VG1nwbotPb5xzFsw5RF4Wnp2G3dWPM3g==
254+
"@apollo/client@^3.13.1":
255+
version "3.13.1"
256+
resolved "https://registry.yarnpkg.com/@apollo/client/-/client-3.13.1.tgz#c0633c69c5446967b0e517a590595eeea61dd176"
257+
integrity sha512-HaAt62h3jNUXpJ1v5HNgUiCzPP1c5zc2Q/FeTb2cTk/v09YlhoqKKHQFJI7St50VCJ5q8JVIc03I5bRcBrQxsg==
258258
dependencies:
259259
"@graphql-typed-document-node/core" "^3.1.1"
260260
"@wry/caches" "^1.0.0"
@@ -265,7 +265,6 @@
265265
optimism "^0.18.0"
266266
prop-types "^15.7.2"
267267
rehackt "^0.1.0"
268-
response-iterator "^0.2.6"
269268
symbol-observable "^4.0.0"
270269
ts-invariant "^0.10.3"
271270
tslib "^2.3.0"
@@ -3436,13 +3435,6 @@
34363435
dependencies:
34373436
tslib "^2.3.0"
34383437

3439-
"@wry/trie@^0.4.3":
3440-
version "0.4.3"
3441-
resolved "https://registry.yarnpkg.com/@wry/trie/-/trie-0.4.3.tgz#077d52c22365871bf3ffcbab8e95cb8bc5689af4"
3442-
integrity sha512-I6bHwH0fSf6RqQcnnXLJKhkSXG45MFral3GxPaY4uAl0LYDZM+YDVDAiU9bYwjTuysy1S0IeecWtmq1SZA3M1w==
3443-
dependencies:
3444-
tslib "^2.3.0"
3445-
34463438
"@wry/trie@^0.5.0":
34473439
version "0.5.0"
34483440
resolved "https://registry.yarnpkg.com/@wry/trie/-/trie-0.5.0.tgz#11e783f3a53f6e4cd1d42d2d1323f5bc3fa99c94"
@@ -9494,13 +9486,13 @@ opener@^1.5.2:
94949486
integrity sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==
94959487

94969488
optimism@^0.18.0:
9497-
version "0.18.0"
9498-
resolved "https://registry.yarnpkg.com/optimism/-/optimism-0.18.0.tgz#e7bb38b24715f3fdad8a9a7fc18e999144bbfa63"
9499-
integrity sha512-tGn8+REwLRNFnb9WmcY5IfpOqeX2kpaYJ1s6Ae3mn12AeydLkR3j+jSCmVQFoXqU8D41PAJ1RG1rCRNWmNZVmQ==
9489+
version "0.18.1"
9490+
resolved "https://registry.yarnpkg.com/optimism/-/optimism-0.18.1.tgz#5cf16847921413dbb0ac809907370388b9c6335f"
9491+
integrity sha512-mLXNwWPa9dgFyDqkNi54sjDyNJ9/fTI6WGBLgnXku1vdKY/jovHfZT5r+aiVeFFLOz+foPNOm5YJ4mqgld2GBQ==
95009492
dependencies:
95019493
"@wry/caches" "^1.0.0"
95029494
"@wry/context" "^0.7.0"
9503-
"@wry/trie" "^0.4.3"
9495+
"@wry/trie" "^0.5.0"
95049496
tslib "^2.3.0"
95059497

95069498
[email protected], ora@^5.1.0, ora@^5.4.1:
@@ -10677,11 +10669,6 @@ [email protected], resolve@^1.1.6, resolve@^1.1.7, resolve@^1.12.0, resolve@^1.14.2
1067710669
path-parse "^1.0.7"
1067810670
supports-preserve-symlinks-flag "^1.0.0"
1067910671

10680-
response-iterator@^0.2.6:
10681-
version "0.2.6"
10682-
resolved "https://registry.yarnpkg.com/response-iterator/-/response-iterator-0.2.6.tgz#249005fb14d2e4eeb478a3f735a28fd8b4c9f3da"
10683-
integrity sha512-pVzEEzrsg23Sh053rmDUvLSkGXluZio0qu8VT6ukrYuvtjVfCbDZH9d6PGXb8HZfzdNZt8feXv/jvUzlhRgLnw==
10684-
1068510672
restore-cursor@^3.1.0:
1068610673
version "3.1.0"
1068710674
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-3.1.0.tgz#39f67c54b3a7a58cea5236d95cf0034239631f7e"
@@ -11351,7 +11338,16 @@ string-length@^4.0.1:
1135111338
char-regex "^1.0.2"
1135211339
strip-ansi "^6.0.0"
1135311340

11354-
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
11341+
"string-width-cjs@npm:string-width@^4.2.0":
11342+
version "4.2.3"
11343+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
11344+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
11345+
dependencies:
11346+
emoji-regex "^8.0.0"
11347+
is-fullwidth-code-point "^3.0.0"
11348+
strip-ansi "^6.0.1"
11349+
11350+
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
1135511351
version "4.2.3"
1135611352
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1135711353
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -11393,7 +11389,14 @@ stringify-entities@^4.0.0:
1139311389
character-entities-html4 "^2.0.0"
1139411390
character-entities-legacy "^3.0.0"
1139511391

11396-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
11392+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
11393+
version "6.0.1"
11394+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
11395+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
11396+
dependencies:
11397+
ansi-regex "^5.0.1"
11398+
11399+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1139711400
version "6.0.1"
1139811401
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1139911402
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -12454,7 +12457,7 @@ wildcard@^2.0.0:
1245412457
resolved "https://registry.yarnpkg.com/wildcard/-/wildcard-2.0.1.tgz#5ab10d02487198954836b6349f74fff961e10f67"
1245512458
integrity sha512-CC1bOL87PIWSBhDcTrdeLo6eGT7mCFtrg0uIJtqJUFyK+eJnzl8A1niH56uu7KMa5XFrtiV+AQuHO3n7DsHnLQ==
1245612459

12457-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
12460+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
1245812461
version "7.0.0"
1245912462
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1246012463
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==

0 commit comments

Comments
 (0)