question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fetchMore doesn't set loading to true (beta.52)

See original GitHub issue

Intended outcome:

When calling fetchMore, loading should be set to true.

Actual outcome:

It remains false and the data loads without this status ever changing, even though notifyOnNetworkStatusChange: true has been set on the useQuery

How to reproduce the issue:

Nothing special here:

const { loading, refetch, fetchMore, error, data } = useQuery(qry, {
    key: dataKey,
    variables,
    partialRefetch,
    notifyOnNetworkStatusChange: true,
    onCompleted: data => {
        if (data[dataKey].totalCount) {
            setTotalCount(data[dataKey].totalCount);
        }
    },
});
const loadMore = React.useCallback(
    (options = {}, loadOnTop = false) =>
        fetchMore({
            updateQuery: (previousResult, { fetchMoreResult, variables }) => {
                onUpdateQuery(loadOnTop);
                [...]
                return {
                    ...first,
                    ...last[dataKey],
                };
            },
            ...options,
        })
            .then(onLoadMore)
            .catch(onLoadMoreError),
    [onLoadMore, onLoadMoreError],
);

Versions Apollo client beta.52 System: OS: macOS Mojave 10.14.6 Binaries: Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node Yarn: 1.22.4 - ~/.nvm/versions/node/v12.16.1/bin/yarn npm: 6.14.5 - ~/.nvm/versions/node/v12.16.1/bin/npm Browsers: Chrome: 83.0.4103.61 Safari: 13.1.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:17
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
DanielMarkielcommented, Jul 28, 2020

@benjamn FYI, I found the reason for my problem. In our app we’ve been calling fetchMore like this:

      fetchMore({
        query: GQL_QUERY,
        variables: {
          ...variables,
          cursor,
        },
      });

When I removed query: GQL_QUERY, the loading state started to update correctly. I believe the reason is the line (condition) below: ...(fetchMoreOptions.query ? fetchMoreOptions : { (src/core/ObservableQuery.ts)

Of course we were unnecessarily setting the query option, but since it worked in v2 I think it’s an undescribed breaking change that is worth adding to the migration guide.

5reactions
hatchlicommented, Jun 30, 2020

Happening in rc.10

Read more comments on GitHub >

github_iconTop Results From Across the Web

react apollo - Why would data.loading not become true during ...
I was having the same problem. Turns out you have to opt in by setting notifyOnNetworkStatusChange to true in your options:.
Read more >
Can't get infinite loading with fetchmore to work - Help
I am able to fetch 4 new results of data, but the issue is, the older data is disappearing.
Read more >
subscribeToMore and fetchMore for the same querry using ...
so I first have a useQuerry: const { subscribeToMore, data, loading, error, fetchMore } = useQuery( GET_CHANNEL_MESSAGES, { variables: { ...
Read more >
@apollo/client | Yarn - Package Manager
Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components...
Read more >
graphql_flutter 4.0.0-beta.2 | Flutter Package - Pub.dev
fetchMore utility for leveraging the fetch more logic results without using ... @micimize; Fixed Mutation widget's behavior to properly set loading status.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found