A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.gatsbyjs.com/docs/how-to/querying-data/using-gatsby-without-graphql/ below:

Website Navigation


Gatsby without GraphQL | Gatsby

Most examples in the Gatsby docs and on the web at large focus on leveraging source plugins to manage your data in Gatsby sites. However, source plugins (or even Gatsby nodes) aren’t strictly necessary to pull data into a Gatsby site! It’s also possible to use an “unstructured data” approach in Gatsby sites, no GraphQL required.

Note: For our purposes here, “unstructured data” means data “handled outside of Gatsby’s data layer” (we’re using the data directly, and not transforming the data into Gatsby nodes).

The approach: fetch data and use Gatsby’s createPages API

Note: This example is drawn from an example repo built specifically to model how to use this “unstructured data” approach. View the full repo on GitHub.

In your Gatsby project’s gatsby-node.js file, fetch the needed data, and supply it to the createPage action within the createPages API:

On the highlighted lines, the data is being supplied to the page template, where it can be accessed as props:

When might using “unstructured data” make sense?

You may find this approach useful when using Gatsby’s data layer feels a bit too heavy-handed for your project scope.

The pros of using unstructured data The tradeoffs of foregoing Gatsby’s data layer

Using Gatsby’s data layer provides the following benefits:

Learn more about GraphQL in Gatsby.

Working outside of the data layer also means foregoing the optimizations provided by transformer plugins, like:

Another difficulty added when working with unstructured data is that your data fetching code becomes increasingly hairy when you source directly from multiple locations.

The Gatsby recommendation

If you’re building a small site, one efficient way to build it is to pull in unstructured data as outlined in this guide, using createPages API, and then if the site becomes more complex later on, you move on to building more complex sites, or you’d like to transform your data, follow these steps:

  1. Check out the Plugin Library to see if the source plugins and/or transformer plugins you’d like to use already exist
  2. If they don’t exist, read the Plugin Authoring guide and consider building your own!
Further reading

Start building today on

Netlify!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4