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.

query results are undefined during loading (due to breaking change in @apollo/client v3)

See original GitHub issue

There was an intentional breaking change in Apollo Client 3.0.0.

When refetching or when using loadMore, results and totalCount revert temporarily to undefined.

For in-depth information and debate, see threads like

It could impact Vulcan in a number of ways, but so far I have only been looking at multi2.js. See Vulcan discussion at https://vulcanjs.slack.com/archives/C2LJQHTLP/p1601657376018800

A possible solution is to update to @apollo/client@3.3.0-beta.6 and override useQuery. Or change https://github.com/VulcanJS/Vulcan/blob/78d0e99dd8cde19b6da04561c27a8e040ef8ae7f/packages/vulcan-core/lib/modules/containers/multi2.js#L110-L113 to something like this:

  const { refetch, networkStatus, error, fetchMore, graphQLErrors, data, previousData } = returnedProps
  const existingData = data ?? previousData
  const results = existingData && existingData[resolverName] && existingData[resolverName].results;
  const totalCount = existingData && existingData[resolverName] && existingData[resolverName].totalCount;

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-burelcommented, Oct 9, 2020

results is a Vulcan specific shortcut (btw in NPM version I renamed it documents for consistency with mutations) so we are free to implement whatever default behaviour we want, no need for an option, and I think what you proposed is the best approach as it prevents a breaking change in Vulcan. People can still access the default data object from Apollo if they want the default behaviour.

0reactions
GraemeFultoncommented, Dec 5, 2020

I’m using oldschool react classes, so keep the results in component state. Then I check and update the results in componentDidUpdate, and render from the state’s copy:

    constructor(props) {
        super(props)
        this.state = {
            results: props.results
        }
    }

    componentDidUpdate(prevProps, prevState) {
        if (this.props.results && (this.props.results != prevProps.results)) {
            if (this.props.results.length > 0) {
                this.setState({
                    results: this.props.results
                })
            }
        }
    }

render() {
  <>
      {this.state.results && this.state.results.map(user => {
        return (
          <ProfileCard user={user} />
          );
      }) 
    }
  </>
}

Then showing loading state based on whether there are results:

{(!this.props.results && this.props.results!==0) && 'Loading...'}

It’s not ideal but does the trick for now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating to Apollo Client 3.0 - Apollo GraphQL Docs
Breaking Changes : useQuery no longer maintains the previously fetched results in its data result when loading new data. Instead, when new data...
Read more >
@apollo/client - Awesome JS
Revert use of cloneDeep to clone options when fetching queries. ... whose addition in #8699 was a breaking change (starting in Apollo Client...
Read more >
@apollo/client | Yarn - Package Manager
@apollo/client. 3.7.3. Patch Changes. #10334 7d923939d Thanks @jerelmiller! - Better handle deferred queries that have cached ...
Read more >
Migrating to React Query 4 - TanStack
Breaking Changes v4 is a major version, so there are some breaking ... cases that cannot be found by the code mod, so...
Read more >
Integrating GraphQL Code Generator in your frontend ...
We can't count of the fields to be there because they GraphQL query can change, and it's not connected to our code at...
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