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

errorPolicy is not defined on FetchMoreQueryOptions interface for fetchMore #12297

Open
dlin303 opened this issue Jan 22, 2025 · 0 comments · May be fixed by #12298
Open

errorPolicy is not defined on FetchMoreQueryOptions interface for fetchMore #12297

dlin303 opened this issue Jan 22, 2025 · 0 comments · May be fixed by #12298

Comments

@dlin303
Copy link

dlin303 commented Jan 22, 2025

Issue Description

The fetchMore function doesn't take in an errorPolicy in its FetchMoreQueryOptions:

export interface FetchMoreQueryOptions<TVariables, TData = any> {
/** {@inheritDoc @apollo/client!QueryOptionsDocumentation#query:member} */
query?: DocumentNode | TypedDocumentNode<TData, TVariables>;
/** {@inheritDoc @apollo/client!QueryOptionsDocumentation#variables:member} */
variables?: Partial<TVariables>;
context?: DefaultContext;
}

However, under the hood, if errorPolicy for fetchMore is specified, fetchMore will perform a shallow merge of its options with the original query, with the specified FetchMoreQueryOptions taking precedence.

We should expose the errorPolicy type in FetchMoreQueryOptions to remove ambiguity surrounding its behavior when using TypeScript.

Other notes:

  • If variables is included as an option for fetchMore, the shallow merge will succeed and fetchMore will inherit the errorPolicy from the original query.
  • If query is included as an option for fetchMore, the original query options will be disregarded (all options will revert to their default values).

Discord discussion: https://discord.com/channels/1022972389463687228/1329263008542625804/1329263008542625804

Link to Reproduction

https://codesandbox.io/p/sandbox/repro-11612-forked-rmdvfd?file=%2Fsrc%2FApp.js

Reproduction Steps

Click 'Query' button to fire off original query. Click 'fetchMore' button to paginate with the 'fetchMore' call which respects the specified errorPolicy in its options. The current type definition of FetchMoreQueryOptions would have you think otherwise.

Note: that if you remove the 'errorPolicy' from fetchMore and specify the query option, the pagination call will fail as it no longer inherits the original errorPolicy: "all".

@apollo/client version

3.9.5

@dlin303 dlin303 changed the title errorPolicy is not defined on FetchMoreOptions interface for fetchMore errorPolicy is not defined on FetchMoreQueryOptions interface for fetchMore Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant