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.

The cache doesn't work if multiple GraphQL components rendered in the same level.

See original GitHub issue

The cache doesn’t work if multiple GraphQL components rendered in the same level.

Intended outcome: If you have components using the same query, there should be only one request.

import { graphql } from 'react-apollo'
import gql from 'graphql-tag'

const query = gql`{ allPosts { title id } }`

class Test extends Component {
  render () {
    console.log(this.props)
    return (
      <div>123</div>
    )
  }
}

const GraphQLTest = graphql(query)(Test)
// render in a parent component
...
              <GraphQLTest />
              <GraphQLTest />
...

Actual outcome: It actually fires multiple requests.

How to reproduce the issue: I create a repo to reproduce this: https://build-nhpmxggvzn.now.sh/ image

https://build-nhpmxggvzn.now.sh/lazy image

PS: cixmkt2ul01q00122mksg82pn are the GraphQL requests.

Versions

  • apollo-client@2.0.2
  • apollo-cache-inmemory:@1.0.0
  • apollo-link@1.0.0
  • apollo-link-http@1.1.0
  • apollo-client-preset@1.0.2
  • graphql@0.11.7
  • graphql-tag@2.5.0
  • react-apollo@2.0.0

This is also discussed in #2444

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

GraphQL query best practices
If two otherwise identical queries have different hardcoded argument values, they're considered entirely different operations by your GraphQL server's cache.
Read more >
useMutation updates cache but does not re-render ... - GitHub
I have the same useQuery in two components. When the cache gets updated the re-render of the second component doesn't happen.
Read more >
How to invalidate cached data in Apollo and handle updating ...
js component does not get re rendered and the Query will not be re run. I believe that the reason using cache.data.delete does...
Read more >
Managing State with React and Apollo Client | DoltHub Blog
We haven't utilized the cache this way in our application, mostly because we started using GraphQL before Apollo 3 came out and the...
Read more >
How to fetch data in React with performance in mind
The answer is still the same - no, it won't. When we write const child = <Child /> we don't “render” Child component....
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