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

Use Partial<TVariables> typing for fetchMore variables, rather than Pick<TVariables, K> #7476

Merged
merged 2 commits into from
Feb 9, 2021
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 @@ -20,6 +20,9 @@ TBD
- Always use `POST` request when falling back to sending full query with `@apollo/client/link/persisted-queries`. <br/>
[@rieset](https://github.com/rieset) in [#7456](https://github.com/apollographql/apollo-client/pull/7456)

- The `FetchMoreQueryOptions` type now takes two instead of three type parameters (`<TVariables, TData>`), thanks to using `Partial<TVariables>` instead of `K extends typeof TVariables` and `Pick<TVariables, K>`. <br/>
[@ArnaudBarre](https://github.com/ArnaudBarre) in [#7476](https://github.com/apollographql/apollo-client/pull/7476)

### Documentation
TBD

Expand Down
8 changes: 2 additions & 6 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ export class ObservableQuery<
);
}

public fetchMore<K extends keyof TVariables>(
fetchMoreOptions: FetchMoreQueryOptions<TVariables, K, TData> &
public fetchMore(
fetchMoreOptions: FetchMoreQueryOptions<TVariables, TData> &
FetchMoreOptions<TData, TVariables>,
): Promise<ApolloQueryResult<TData>> {
const combinedOptions = {
Expand Down Expand Up @@ -412,10 +412,6 @@ once, rather than every time you call fetchMore.`);
*
* @param variables: The new set of variables. If there are missing variables,
* the previous values of those variables will be used.
*
* @param tryFetch: Try and fetch new results even if the variables haven't
* changed (we may still just hit the store, but if there's nothing in there
* this will refetch)
*/
public setVariables(
variables: TVariables,
Expand Down
4 changes: 2 additions & 2 deletions src/core/watchQueryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ export interface WatchQueryOptions<TVariables = OperationVariables, TData = any>
) => WatchQueryFetchPolicy);
}

export interface FetchMoreQueryOptions<TVariables, K extends keyof TVariables, TData = any> {
export interface FetchMoreQueryOptions<TVariables, TData = any> {
query?: DocumentNode | TypedDocumentNode<TData, TVariables>;
variables?: Pick<TVariables, K>;
variables?: Partial<TVariables>;
context?: any;
}

Expand Down
4 changes: 2 additions & 2 deletions src/react/data/QueryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ export class QueryData<TData, TVariables> extends OperationData {
private obsRefetch = (variables?: Partial<TVariables>) =>
this.currentObservable?.refetch(variables);

private obsFetchMore = <K extends keyof TVariables>(
fetchMoreOptions: FetchMoreQueryOptions<TVariables, K, TData> &
private obsFetchMore = (
fetchMoreOptions: FetchMoreQueryOptions<TVariables, TData> &
FetchMoreOptions<TData, TVariables>
) => this.currentObservable!.fetchMore(fetchMoreOptions);

Expand Down
2 changes: 1 addition & 1 deletion src/react/hoc/__tests__/queries/api.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe('[queries] api', () => {
};

type Data = typeof data1;
type Variables = typeof vars1;
type Variables = { cursor: number | undefined };

const link = mockSingleLink(
{ request: { query, variables: vars1 }, result: { data: data1 } },
Expand Down
2 changes: 1 addition & 1 deletion src/react/hoc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface QueryControls<
loading: boolean;
variables: TGraphQLVariables;
fetchMore: (
fetchMoreOptions: FetchMoreQueryOptions<TGraphQLVariables, any, TData> &
fetchMoreOptions: FetchMoreQueryOptions<TGraphQLVariables, TData> &
FetchMoreOptions<TData, TGraphQLVariables>
) => Promise<ApolloQueryResult<TData>>;
refetch: (variables?: TGraphQLVariables) => Promise<ApolloQueryResult<TData>>;
Expand Down
7 changes: 3 additions & 4 deletions src/react/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ export type ObservableQueryFields<TData, TVariables> = Pick<
| 'refetch'
| 'variables'
> & {
fetchMore: (<K extends keyof TVariables>(
fetchMoreOptions: FetchMoreQueryOptions<TVariables, K, TData> &
fetchMore: ((
fetchMoreOptions: FetchMoreQueryOptions<TVariables, TData> &
FetchMoreOptions<TData, TVariables>
) => Promise<ApolloQueryResult<TData>>) &
(<TData2, TVariables2, K extends keyof TVariables2>(
(<TData2, TVariables2>(
fetchMoreOptions: { query?: DocumentNode | TypedDocumentNode<TData, TVariables> } & FetchMoreQueryOptions<
TVariables2,
K,
TData
> &
FetchMoreOptions<TData2, TVariables2>
Expand Down