Closed denisyilmaz closed 1 year ago
... I found the issue. A fragment of mine was using a field twice (with an alias on second usage). The subselection did not had a id
in it. Adding the id
the query is not fetched a second time on the browser.
For future reference and others who might have similar issues, here an example query that was causing the cache to fail:
fragment Anchor on bodyContent_Field {
__typename
showAnchor
anchorId
label
}
fragment BodyContent on bodyContent_Field {
__typename
id
title
content
}
fragment DefaultPage on defaultPage_Entry {
id
siteId
title
anchors: bodyContent {
...Anchor
}
bodyContent {
...BodyContent
}
}
query GetPageTest($uri: String) {
entry(uri: [$uri]) {
__typename
...DefaultPage
parent {
id
siteId
title
uri
}
children {
id
siteId
title
uri
}
}
}
The fixed version (adding a id
to Anchor
fragment):
fragment Anchor on bodyContent_Field {
__typename
id
showAnchor
anchorId
label
}
We have an angular application with apollo + codegen. We generate the
possibleTypes
with these settings:Which is working great in a non-universal usage. We now wanted to enable Angular Universal and followed the instructions to restore the InMemoryCache of Apollo on the server with Transferstate:
Debugging the
cache.extract()
object i can confirm that the cache is successfully restored on the browser having all Queries and fragments in it.Unfortunately the apollo is not honoring the cache and therefore re-fetching the queries in the browser. Here an example resolver we use:
In the resolver i tried to access the cache with
readQuery()
to check what cache is available on resolver call and this was resulting innull
. Checking the full cache object though showed the entry to be present. So for whatever reason apollo is not using the cached query but rather fetches frech from the server.Now, for a test I removed the
possibleTypes
object from the InMemoryCache config and voilà, the frontend does not load the query again. Of course this is not working now as the fragments are not matched (therefor my frontend is broken) but it shows that the problem is somewhere to find inpossibleTypes
.Is this a known limitation/bug with apollo? I'm rather clueless here how to get rid of that issue. Anyone experience something similar?