gatsby-source-sanity
gatsby-source-sanity copied to clipboard
Clear cache required for resolveReferences to work after adding new object and document type
- Create a new document type (
newPage) - Create a new object type with an array of references to the new document type (
newObject.newPageReferences) - Add the new object type to allowed types in a portable text area (
oldPage.portableTextContent) - Add some sample data
- Deploy GraphQL API
- Build gatsby site
- Query
_rawPortableTextContent(resolveReferences: { maxDepth: 10 })(in a page or via graphiql)
Actual result:
- The reference to the new page type (each item in
newPageReferences) returnsnull - If I clear Gatsby's cache and rebuild,
resolveReferencesstarts working again, andnewPageReferenceswill contain the properties of the linked page. - I get this behaviour on Gatsby Cloud as well
Expected result:
- When building the site (full build), I expected that
resolveReferencesshould result in the page properties being returned without a manualgatsby clean.
gatsby@^4.4.0 (4.4.0) gatsby-source-sanity@^7.3.2 (7.3.2)
I believe we are also experiencing this issue which is requiring us to run a yarn clean as part of the build step. This is not ideal since it makes our build much longer.
I've been looking into this exact issue too and have found the following within the sourcesNodes function of gatsby-node.ts within the plugin...
When there is no cache, ALL documents and objects are downloaded into cache with their IDs.
Once a cache has been generated, the second time around a separate procedure is run where documents are "touched" using action.touchNode this is to prevent Gatsby removing the item from the cache. However, this process gets documents only and therefore removes object references where isDocument is false, as they don't get "touched" for Gatsby to keep them.
Therefore the start up procedure and run from cache procedures are caching two different datasets, with the latter deleting much more from cache than it should, causing the references to break.
Thanks for highlighting!
Could this issue be the root of https://www.reddit.com/r/gatsbyjs/comments/uw8jq7/cache_issue_in_netlify/ as well?
Thank you! We're looking into it.