Skip to content

Commit

Permalink
Fix typescript issue with defaultOptions in constructor
Browse files Browse the repository at this point in the history
When the new `QueryBaseOptions` and `QueryOptions` interfaces
were created in
eb89b23,
`ModifiableWatchQueryOptions` was replaced by `QueryOptions`
when checking the `query` `defaultOptions` used in the
Apollo Client constructor. Unfortunately, this introduced a
small type check bug since the `query` property in `QueryOptions`
is a mandatory property, whereas `ModifiableWatchQueryOptions`
did not include this property. This commit replaces the use of
`QueryOptions` with `QueryBaseOptions` when type checking
`query` in `defaultOptions`, since `QueryBaseOptions` doesn't
have a `query` property.

Fixes #3583.
  • Loading branch information
hwillson committed Jun 14, 2018
1 parent e4afc8b commit 12f88ec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/apollo-client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

- Export the `QueryOptions` interface, to make sure it can be used by other
projects (like `apollo-angular`).
- Fixed an issue caused by typescript changes to the constructor
`defaultOptions` param, that prevented `query` defaults from passing type
checks.
[Issue #3583](https://github.com/apollographql/apollo-client/issues/3583)
[PR #]()

### 2.3.3

Expand Down
5 changes: 3 additions & 2 deletions packages/apollo-client/src/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ObservableQuery } from './core/ObservableQuery';
import { Observable } from './util/Observable';

import {
QueryBaseOptions,
QueryOptions,
WatchQueryOptions,
SubscriptionOptions,
Expand All @@ -34,7 +35,7 @@ import { version } from './version';

export interface DefaultOptions {
watchQuery?: ModifiableWatchQueryOptions;
query?: QueryOptions;
query?: QueryBaseOptions;
mutate?: MutationBaseOptions;
}

Expand Down Expand Up @@ -246,7 +247,7 @@ export default class ApolloClient<TCacheShape> implements DataProxy {
// XXX Overwriting options is probably not the best way to do this long
// term...
if (this.disableNetworkFetches && options.fetchPolicy === 'network-only') {
options = { ...options, fetchPolicy: 'cache-first' } as WatchQueryOptions;
options = { ...options, fetchPolicy: 'cache-first' } as QueryOptions;
}

return this.queryManager.query<T>(options);
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
ApolloCurrentResult,
} from './core/ObservableQuery';
export {
QueryBaseOptions,
QueryOptions,
WatchQueryOptions,
MutationOptions,
Expand Down

0 comments on commit 12f88ec

Please sign in to comment.