Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge QueryBaseOptions, QueryOptions, and ModifiableQueryOptions into one type. #7136

Merged
merged 2 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
- Unsubscribing the last observer from an `ObservableQuery` will once again unsubscribe from the underlying network `Observable` in all cases, as in Apollo Client 2.x, allowing network requests to be cancelled by unsubscribing. <br/>
[@javier-garcia-meteologica](https://github.com/javier-garcia-meteologica) in [#7165](https://github.com/apollographql/apollo-client/pull/7165) and [#7170](https://github.com/apollographql/apollo-client/pull/7170).

- The independent `QueryBaseOptions` and `ModifiableWatchQueryOptions` interface supertypes have been eliminated, and their fields are now defined by `QueryOptions`. <br/>
[@DCtheTall](https://github.com/DCtheTall) in [#7136](https://github.com/apollographql/apollo-client/pull/7136)

## Improvements

- Support inheritance of type and field policies, according to `possibleTypes`. <br/>
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,26 @@ describe('ApolloClient', () => {

client.stop();
});

it('should be able to set all default query options', () => {
new ApolloClient({
link: ApolloLink.empty(),
cache: new InMemoryCache(),
defaultOptions: {
query: {
query: {kind: 'Document', definitions: []},
variables: {foo: 'bar'},
errorPolicy: 'none',
context: null,
fetchPolicy: 'cache-first',
pollInterval: 100,
notifyOnNetworkStatusChange: true,
returnPartialData: true,
partialRefetch: true,
},
},
});
});
});

describe('clearStore', () => {
Expand Down
1 change: 0 additions & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export {
UpdateQueryOptions,
} from './ObservableQuery';
export {
QueryBaseOptions,
QueryOptions,
WatchQueryOptions,
MutationOptions,
Expand Down
19 changes: 3 additions & 16 deletions src/core/watchQueryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export type WatchQueryFetchPolicy = FetchPolicy | 'cache-and-network';
export type ErrorPolicy = 'none' | 'ignore' | 'all';

/**
* Common options shared across all query interfaces.
* Query options.
*/
export interface QueryBaseOptions<TVariables = OperationVariables, TData = any> {
export interface QueryOptions<TVariables = OperationVariables, TData = any> {
/**
* A GraphQL document that consists of a single query to be sent down to the
* server.
Expand All @@ -59,24 +59,12 @@ export interface QueryBaseOptions<TVariables = OperationVariables, TData = any>
* Context to be passed to link execution chain
*/
context?: any;
}

/**
* Query options.
*/
export interface QueryOptions<TVariables = OperationVariables, TData = any>
extends QueryBaseOptions<TVariables, TData> {
/**
* Specifies the {@link FetchPolicy} to be used for this query
*/
fetchPolicy?: FetchPolicy;
}

/**
* We can change these options to an ObservableQuery
*/
export interface ModifiableWatchQueryOptions<TVariables = OperationVariables, TData = any>
extends QueryBaseOptions<TVariables, TData> {
/**
* The time interval (in milliseconds) on which this query should be
* refetched from the server.
Expand Down Expand Up @@ -106,8 +94,7 @@ export interface ModifiableWatchQueryOptions<TVariables = OperationVariables, TD
* Watched query options.
*/
export interface WatchQueryOptions<TVariables = OperationVariables, TData = any>
extends QueryBaseOptions<TVariables, TData>,
ModifiableWatchQueryOptions<TVariables, TData> {
extends Omit<QueryOptions<TVariables, TData>, 'fetchPolicy'> {
/**
* Specifies the {@link FetchPolicy} to be used for this query.
*/
Expand Down