You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
importReactfrom'react';import{Query}from'react-apollo';importgqlfrom'graphql-tag';constServerInfo=gql` query ServerInfo { serverInfo { announcement } }`;constHomes=gql` query Homes { homes { name address } }`;exportconstHello=()=>(<divclassName="Hello"><h1>In the future this will be the XPTO web app</h1><Queryquery={ServerInfo}fetchPolicy={'cache-only'}>{({ loading, error, data })=>{console.count(`serverInfo data: ${!!data.serverInfo} loading: ${loading}`);if(loading&&!data.serverInfo)return<p>Loading...</p>;if(error)return<p>Error :(</p>;return<h3>{`Server announcement: ${data.serverInfo.announcement}`}</h3>;}}</Query><Queryquery={Homes}fetchPolicy={'cache-only'}>{({ loading, error, data })=>{console.count(`homes data: ${!!data.homes} loading: ${loading}`);if(loading&&!data.homes)return<p>Loading...</p>;if(error)return<p>Error :(</p>;return(<React.Fragment><h2>Home list from server:</h2>{data.homes.map(({ name, address },index)=>(<divkey={index}><p>{`${name} - ${address}`}</p></div>))}</React.Fragment>);}}</Query></div>);
Local Storage:
apollo-cache-persist:
{"$ROOT_QUERY.serverInfo":{"announcement":"Please keep away! This server belongs to XPTO.","__typename":"ServerInfo"},"ROOT_QUERY":{"serverInfo":{"type":"id","generated":true,"id":"$ROOT_QUERY.serverInfo","typename":"ServerInfo"},"homes":[{"type":"id","generated":true,"id":"ROOT_QUERY.homes.0","typename":"Home"},{"type":"id","generated":true,"id":"ROOT_QUERY.homes.1","typename":"Home"}]},"ROOT_QUERY.homes.0":{"name":"Test1","address":"Venda do Pinheiro","__typename":"Home"},"ROOT_QUERY.homes.1":{"name":"Test2","address":"Lisboa","__typename":"Home"}}}
Version
This versions is the ones I used on this tiny example. With the other big project I'm using older versions.
apollo-client@2.4.2
react-apollo@2.2.1
apollo-boost@0.1.16
apollo-cache@1.1.17
apollo-cache-inmemory@^1.3.0
apollo-cache-inmemory@^1.2.10 (not sure about wich one is used as I have the 2 on yarn.lock)
apollo-cache-persist@^0.1.1
The text was updated successfully, but these errors were encountered:
rcacheira
changed the title
cache-only querie
cache-only queries render 3 times
Sep 30, 2018
Hey @rcacheira - does cache-first ever actually grab the data from the cache? It seems like based on apollographql/apollo-client#3452 that caching is totally broken in ApolloClient at the moment ...
'cache-only' queries render 3 times with
loading===false
and the same data.I've detected this error on another big project using 'graphql' and 'compose', here I'm showing a little example using v2 queries.
Intended console outcome:
Actual console outcome:
How to reproduce the issue:
Index.tsx:
App.tsx:
Hello.tsx:
Local Storage:
apollo-cache-persist:
Version
This versions is the ones I used on this tiny example. With the other big project I'm using older versions.
The text was updated successfully, but these errors were encountered: