diff --git a/README.md b/README.md index 943265d..ef1ba86 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ plugins: [ options: { apiURL: `http://localhost:1337`, queryLimit: 1000, // Default to 100 + publicationState: 'preview', // Default to live contentTypes: [ `article`, `user`, diff --git a/src/fetch.js b/src/fetch.js index b80e7a3..1175395 100644 --- a/src/fetch.js +++ b/src/fetch.js @@ -2,12 +2,12 @@ import axios from 'axios'; import { isObject, forEach, set, castArray, startsWith } from 'lodash'; module.exports = async (endpoint, ctx) => { - const { apiURL, queryLimit, jwtToken, reporter } = ctx; + const { apiURL, queryLimit, publicationState, jwtToken, reporter } = ctx; // Define API endpoint. let apiBase = `${apiURL}/${endpoint}`; - const apiEndpoint = `${apiBase}?_limit=${queryLimit}`; + const apiEndpoint = `${apiBase}?_limit=${queryLimit}&_publicationState=${publicationState}`; reporter.info(`Starting to fetch data from Strapi - ${apiEndpoint}`); diff --git a/src/index.js b/src/index.js index a95ac74..5d1d7ab 100644 --- a/src/index.js +++ b/src/index.js @@ -26,7 +26,13 @@ const fetchEntities = async ({ endpoint }, ctx) => { exports.sourceNodes = async ( { store, actions, cache, reporter, getNode, getNodes, createNodeId }, - { apiURL = 'http://localhost:1337', loginData = {}, queryLimit = 100, ...options } + { + apiURL = 'http://localhost:1337', + loginData = {}, + queryLimit = 100, + publicationState = 'live', + ...options + } ) => { const { createNode, deleteNode, touchNode } = actions; @@ -38,6 +44,7 @@ exports.sourceNodes = async ( createNode, createNodeId, queryLimit, + publicationState, apiURL, jwtToken, reporter,