Search code examples
gatsby

Updating Content on Gatsby Sites


we are building a website where I fetch data from a GraphQL API, the website content is somewhat dynamic, so that we use Apollo Client for some of the content, this makes the website somewhat slow compared to the static sites and is not a great user experience.

I tried binding content with gatsby-source-graphql, for a query that for example fetches a list of items that can be updated every few hours or every few weeks. Having to build to make this data always static is not a very great solution, because we have limited build time and we want to make the content somewhat updated.

Is a custom data source plugin a possible solution for this? or which other solutions are there for content updates, so that we dont have to rebuild?


Solution

  • What you are trying to implement is called webhook, however, due to Gatsby's limitations (being a static site generator) the site must be rebuilt to gather the new data in order to create your new static pages based on your updated content.

    If you think of how Gatsby works (in the build-time it fetches all data-sources and generates a static HTML with all your JavaScript bundle and logic behind) you will see that you can't bypass a new data fetching without rebuilding the site.

    A webhook will create a connection between your CMS and your site, there you trigger a build once the new data is created, updated, or deleted.

    If your content comes from an outer API, and you don't care about SEO, you can create an API request once the user enters your site to populate it with your content, however, you'll lose all the advantages that Gatsby provides.