Skip to content

Commit

Permalink
update gatsby-source-drupal to match new json api endpoint (#3136)
Browse files Browse the repository at this point in the history
* default drupal source to new json api endpoint

allow override if necessary

* update documentation for apiBase option
  • Loading branch information
Tyler Funk authored and KyleAMathews committed Dec 12, 2017
1 parent c92f4cd commit ba36de9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/gatsby-source-drupal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ An example site built with the headless Drupal distro
[ContentaCMS](https://twitter.com/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`
Expand All @@ -20,7 +24,10 @@ https://using-drupal.gatsbyjs.org/
plugins: [
{
resolve: `gatsby-source-drupal`,
options: { baseUrl: `https://live-contentacms.pantheonsite.io/` },
options: {
baseUrl: `https://live-contentacms.pantheonsite.io/`,
apiBase: `api` // optional, defaults to `jsonapi`
},
},
];
```
Expand Down
7 changes: 5 additions & 2 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ const createContentDigest = obj =>

exports.sourceNodes = async (
{ boundActionCreators, getNode, hasNodeChanged, store, cache },
{ baseUrl }
{ baseUrl, apiBase }
) => {
const { createNode } = boundActionCreators

// Default apiBase to `jsonapi`
apiBase = apiBase || `jsonapi`

// Touch existing Drupal nodes so Gatsby doesn't garbage collect them.
// _.values(store.getState().nodes)
// .filter(n => n.internal.type.slice(0, 8) === `drupal__`)
Expand All @@ -36,7 +39,7 @@ exports.sourceNodes = async (
// .lastFetched
// }

const data = await axios.get(`${baseUrl}/api`)
const data = await axios.get(`${baseUrl}/${apiBase}`)
const allData = await Promise.all(
_.map(data.data.links, async (url, type) => {
if (type === `self`) return
Expand Down

0 comments on commit ba36de9

Please sign in to comment.