ISR with WPGraphQL Data
See original GitHub issueI’m attempting to add incremental static regeneration (ISR) to the [slugParent]/[[slugChild]].js
file in order to regenerate pages where the CMS content has changed.
ISR is triggered according to my build logs, but the page content never updates on the frontend after I’ve updated it within the backend of WordPress… maybe it’s not recognizing the WPGraphQL data as having changed? Any help at all would be appreciated!
[slugParent]/[[slugChild]].js
export async function getStaticProps({ params = {} } = {}) {
const { slugParent, slugChild } = params;
// We can use the URI to look up our page and subsequently its ID, so
// we can first contruct our URI from the page params
let pageUri = `/${slugParent}/`;
// We only want to apply deeper paths to the URI if we actually have
// existing children
if (Array.isArray(slugChild) && slugChild.length > 0) {
pageUri = `${pageUri}${slugChild.join('/')}/`;
}
const { page } = await getPageByUri(pageUri);
// In order to show the proper breadcrumbs, we need to find the entire
// tree of pages. Rather than querying every segment, the query should
// be cached for all pages, so we can grab that and use it to create
// our trail
const { pages } = await getAllPages();
const breadcrumbs = getBreadcrumbsByUri(pageUri, pages);
return {
props: {
page,
breadcrumbs,
},
revalidate: 10,
};
}
export async function getStaticPaths() {
const { pages } = await getAllPages();
// Take all the pages and create path params. The slugParent will always be
// the top level parent page, where the slugChild will be an array of the
// remaining segments to make up the path or URI
const paths = pages
.filter(({ uri }) => typeof uri === 'string')
.map(({ uri }) => {
const segments = uri.split('/').filter((seg) => seg !== '');
return {
params: {
slugParent: segments.shift() || '',
slugChild: segments,
},
};
});
return {
paths,
fallback: 'blocking',
};
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Security - WPGraphQL
Anything that is publicly exposed by WordPress is publicly exposed by WPGraphQL, and any data that requires a user to be authenticated to...
Read more >Users - WPGraphQL
User Mutations ... WPGraphQL provides mutations (the ability to change data through GraphQL) for Users. WPGraphQL adheres to core access control rights, ensuring ......
Read more >Intro to GraphQL - WPGraphQL
So, GraphQL is a specification for a Query Language for interacting with API data as a data graph. GraphQL isn't tied to any...
Read more >Authentication and Authorization - WPGraphQL
These plugins make use of sending data in the Headers of requests and validating the credentials and setting the user before execution of...
Read more >WPGraphQL Concepts
WPGraphQL has a “Model Layer”, or a series of PHP Classes that take WordPress objects, such as WP_Post , WP_Comment , etc and...
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
Hey @idpelago! Check out Setting a Fetch Policy, and I misspoke above it’s actually
network-only
, notnetwork-first
.For example:
Hey @colbyfayock! Thank you for the reply - turns out it was a caching issue HA! I’m using ApolloClient and it was just returning the cached Apollo results instead of the new data. Had to tweak my caching keys, and changed a few to
network-first
and ISR appears to be working as expected. Closing as a non-issue!