The cache doesn't work if multiple GraphQL components rendered in the same level.
See original GitHub issueThe 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/
https://build-nhpmxggvzn.now.sh/lazy
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:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @jbaxleyiii
I did verify your latest publish fix the problem. https://github.com/xcv58/apollo-client-cache-same-query/commit/bea448e4ae21d8b2607192cdb5c19b90342200ca https://github.com/apollographql/apollo-link/commit/685b07dd024b2e97a0929ac841ba5e1d19aa042a
Thank you very much!
Thanks @jbaxleyiii I guess this may be related to another issue: https://github.com/apollographql/apollo-link/issues/225