DEV Community

Discussion on: Configuring WordPress as a headless CMS with Next.js

Collapse
 
tompearson profile image
Tom Pearson

Hi Rob, thanks for taking the time to write this up.
A question though: Why use GraphQL instead of the WordPress REST API?

Collapse
 
codertravelerme profile image
sb • Edited

I believe it's due to a faster performance - with the rest api, you're always ending up retrieving data from many more db columns than you need to, for any given functionality you're building. With graphql, you're decreasing the data being transmitted over the API, by only choosing just the columns you need.

Collapse
 
codertravelerme profile image
sb • Edited

.. but as an argument against my own reply, if you don't want to learn/use graphql, I think the improvement in the newest nextjs incremental static generation could mitigate the performance loss if you went ahead and just used WP REST Api. You could configure nextjs to pull data from the server every 2 minutes at the most or something like that.

Thread Thread
 
jrhager84 profile image
Joel R Hager

You could also use SWR to serve stale state after the page time exceeds the last regen, it'll serve one stale state, and then trigger a revalidate in the background.

Thread Thread
 
adamsoderstrom profile image
Adam Söderström • Edited

I think it still would be wise to use GraphQL, since ISR from Next still pre-bundles the complete chunk of static props.

If you then want to slim down the REST response, you'll have to do one of the following:

  • manually "chopping off" data that is not used in the NextJS application.
  • Add query parameters to filter it in the WP-response.