@aposudevsky/gatsby-source-drupal
v3.0.26
Published
Gatsby source plugin for building websites using the Drupal CMS as a data source. Added possibility of request customization by adding headers and get params
Downloads
3
Maintainers
Readme
gatsby-source-drupal
Source plugin for pulling data (including images) into Gatsby from Drupal sites.
Pulls data from Drupal 8 sites with the Drupal JSONAPI module installed.
An example site built with the headless Drupal distro ContentaCMS is at https://using-drupal.gatsbyjs.org/
apiBase
Option allows changing the API entry point depending on the version of
jsonapi used by your Drupal instance. The default value is jsonapi
, which has
been used since jsonapi version 8.x-1.0-alpha4
.
Install
npm install --save gatsby-source-drupal
How to use
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-drupal`,
options: {
baseUrl: `https://live-contentacms.pantheonsite.io/`,
apiBase: `api`, // optional, defaults to `jsonapi`
},
},
],
}
Basic Auth
You can use basicAuth
option if your site is protected by basicauth.
First, you need a way to pass environment variables to the build process, so secrets and other secured data aren't committed to source control. We recommend using dotenv
which will then expose environment variables. Read more about dotenv and using environment variables here. Then we can use these environment variables and configure our plugin.
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-drupal`,
options: {
baseUrl: `https://live-contentacms.pantheonsite.io/`,
apiBase: `api`, // optional, defaults to `jsonapi`
basicAuth: {
username: process.env.BASIC_AUTH_USERNAME,
password: process.env.BASIC_AUTH_PASSWORD,
},
},
},
],
}
Request Headers
You can add optional request headers to the request using headers
param.
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-drupal`,
options: {
baseUrl: `https://live-contentacms.pantheonsite.io/`,
apiBase: `api`, // optional, defaults to `jsonapi`
headers: {
'Host': 'https://example.com', // any valid request header here
}
},
},
],
}
GET Params
You can append optional GET request params to the request url using params
option.
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-drupal`,
options: {
baseUrl: `https://live-contentacms.pantheonsite.io/`,
apiBase: `api`, // optional, defaults to `jsonapi`
params: {
'api-key': 'your-api-key-header-here', // any valid key value pair here
}
},
},
],
}
How to query
You can query nodes created from Drupal like the following:
{
allArticle {
edges {
node {
title
internalId
created(formatString: "DD-MMM-YYYY")
}
}
}
}