Gatsby Training
  • About this training
  • Fundamentals
    • React
    • Gatsby
    • GraphQL
    • JAMStack
    • JSX
    • Webpack
  • Getting Started
    • Build your first Gatsby site
    • Project structure
    • Component structure
  • Components
    • About Components
    • Eyebrow
    • Button
    • Heading
    • Working with CSS
    • Movie Card
  • Gatsby Core Components
    • Gatsby Link
    • Gatsby Image
  • Data and GraphQL
    • Data sources
    • Connecting a data source
    • Using the GraphQL playground
  • CreatePages
    • createPages Function
    • Create a template
  • Resources
    • Gatsby and React Resources
    • Other resources
Powered by GitBook
On this page
  • The File System Source Plugin
  • The Drupal Source Plugin
  • Configure Gatsby to pull data from Drupal

Was this helpful?

  1. Data and GraphQL

Connecting a data source

PreviousData sourcesNextUsing the GraphQL playground

Last updated 4 years ago

Was this helpful?

To connect a data source to Gatsby you’ll need to first add the relevant plugin. Plugins are added via the gatsby-config.js file. The options and requirements for each source plugin can be found on the site.

The File System Source Plugin

We added the to allow us to reference local files within the filesystem or our Gatsby site (e.g., the files included in the images directory under src/global/images) We have already added the configuration for the plugin to the gatsby-config.js file (see line 12), but if you were to do this on your own, you would need to first install the plugin:

npm install --save gatsby-source-filesystem

Then add the plugin configuration to the gatsby-config.js file, and the data source will be available in Gatsby from that point on.

The Drupal Source Plugin

About JSON API: Before Gatsby can pull data from Drupal, the needs to be enabled and configured

Just like the File System Source plugin, the has already been added (see line 19), but if you were to set this up on your own you’d follow the same process:

npm install --save gatsby-source-drupal

Then add the plugin configuration to the gatsby-config.js file, and data from your Drupal site will then be available in Gatsby.

Be sure to review the different options available for the source plugins on the GatsbyJS site. For example, with the Drupal source plugin you can provide basic authentication credentials if you wanted to keep your Drupal site behind a basic authentication, but still make it available to Gatsby.

Configure Gatsby to pull data from Drupal

Inside gatsby-config.js configure the Drupal Source Plugin by providing the baseURL for Drupal as well as the apiBase. See example:

// In your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-drupal`,
      options: {
        baseUrl: `http://nitflex.lndo.site/`,
        apiBase: `api`, // optional, defaults to `jsonapi`
      },
    },
  ],
}

NOTE: As long as Drupal's API endpoint is jsonapi, the apiBase line can be omitted.

gatsbyjs.org
File System Source Plugin
JSON API Module
Drupal Source Plugin