Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Publication state support for fetching draft content #184

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ plugins: [
options: {
apiURL: `http://localhost:1337`,
queryLimit: 1000, // Default to 100
publicationState: 'preview', // Default to live
contentTypes: [
`article`,
`user`,
Expand Down
4 changes: 2 additions & 2 deletions src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -38,6 +44,7 @@ exports.sourceNodes = async (
createNode,
createNodeId,
queryLimit,
publicationState,
apiURL,
jwtToken,
reporter,
Expand Down