Skip to content

fetchMore doesn't trigger callback on graphql/network error #6857

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

Open
Necroskillz opened this issue Aug 18, 2020 · 8 comments
Open

fetchMore doesn't trigger callback on graphql/network error #6857

Necroskillz opened this issue Aug 18, 2020 · 8 comments

Comments

@Necroskillz
Copy link

Intended outcome:
When an error occurs while using fetchMore to get the next page (either response with errors or network error), the query should be notified of it when using errorPolicy: 'all'.

Actual outcome:
GQL Request failed and the watch callback was not called.

How to reproduce the issue:

My case: Use relay pagination, have a query which uses { fetchPolicy: 'cache-and-network', nextFetchPolicy: 'cache-first', errorPolicy: 'all' }, have a callback which handles errors property. Load initial page, then either have invalid after cursor value in fetchMore to have grapql endpoint fail when parsing it, or go offline. Then try to load the next page.

Versions

  System:
    OS: Windows 10 10.0.18362
  Binaries:
    Node: 12.18.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 84.0.4147.125
    Edge: Spartan (44.18362.449.0)
  npmPackages:
    @apollo/client: ^3.1.3 => 3.1.3
    apollo-angular: ^2.0.3 => 2.0.3
@raduflp
Copy link

raduflp commented Sep 15, 2020

I can confirm that this is reproducible on @apollo/client: 3.2.0 even with the default errorPolicy, fetchPolicy, nextFetchPolicy values

@hwillson
Copy link
Member

If someone can provide a small runnable reproduction that demonstrates this happening with @apollo/client@latest, we'll take a closer look. Thanks!

dylanwulf added a commit to dylanwulf/react-apollo-error-template that referenced this issue Jun 8, 2021
@dylanwulf
Copy link
Contributor

@hwillson Here is my reproduction (use branch fetchmore-error-callback): https://github.com/dylanwulf/react-apollo-error-template/tree/fetchmore-error-callback

If the error policy is none, then the fetchMore function will throw but onError will NOT be called. If the error policy is all, then fetchMore will NOT throw and the onError callback will STILL NOT be called.

I think part of the problem here is that the documentation is very unclear. When fetchMore results in an error, is it supposed to call onError? Is it supposed to throw? When the error policy is all, is onError supposed to be called or not? I have no idea.

@mohamedjkr
Copy link

mohamedjkr commented Jan 5, 2023

I can confirm that this is reproducible on @apollo/client: 3.7.3 with errorPolicy: default | 'none'

@mathbalduino
Copy link

Still happening

@malininss
Copy link

Confirm the problem

@ossamaweb
Copy link

ossamaweb commented Jul 11, 2024

In my case, I am merging the previous and the new results. I had to throw the error first from withinupdateQuery

fetchMore({
        variables: {
          ...getTemplateVersionsQueryVars,
        },
        updateQuery: (previousQueryResult, { fetchMoreResult }) => {
          if (!fetchMoreResult) return previousQueryResult;

          if (fetchMoreResult instanceof ApolloError) {
            throw fetchMoreResult;
          }
          return {
            getTemplateVersions: {
              ...fetchMoreResult.getTemplateVersions,
              edges: [
                ...(previousQueryResult.getTemplateVersions.edges ?? []),
                ...(fetchMoreResult.getTemplateVersions.edges ?? []),
              ],
            },
          };
        },
      }).catch((error) => console.log({ fetchMoreError: error }));

https://stackoverflow.com/questions/54437901/how-to-error-handle-in-fetchmore-pagination/78734951#78734951

@keithfrazier25
Copy link

Linking in this issue for anyone that ends up here, #12352

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants