Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[1.0] Update Contentful source plugin to fetch max 1000 items #1209

Merged
merged 1 commit into from
Jun 20, 2017
Merged
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
7 changes: 5 additions & 2 deletions packages/gatsby-plugin-typescript/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ module.exports.modifyWebpackConfig = ({ config }, { compilerOptions }) => {
const opts = { compilerOptions: copts, transpileOnly: true }

// Load gatsby babel plugin to extract graphql query
const extractQueryPlugin = path.resolve(__dirname, `../gatsby/dist/utils/babel-plugin-extract-graphql.js`)
const extractQueryPlugin = path.resolve(
__dirname,
`../gatsby/dist/utils/babel-plugin-extract-graphql.js`
)

config.loader(`typescript`, {
test,
loaders: [
`babel?${JSON.stringify({ plugins:[extractQueryPlugin] })}`,
`babel?${JSON.stringify({ plugins: [extractQueryPlugin] })}`,
`ts-loader?${JSON.stringify(opts)}`,
],
})
Expand Down
23 changes: 20 additions & 3 deletions packages/gatsby-source-contentful/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const contentful = require(`contentful`)
const crypto = require(`crypto`)
const stringify = require("json-stringify-safe")
const stringify = require(`json-stringify-safe`)

const digest = str => crypto.createHash(`md5`).update(str).digest(`hex`)

Expand All @@ -27,11 +27,16 @@ exports.sourceNodes = async (

let contentTypes
try {
contentTypes = await client.getContentTypes()
contentTypes = await client.getContentTypes({ limit: 1000 })
} catch (e) {
console.log(`error fetching content types`, e)
}
console.log(`contentTypes fetched`, contentTypes.items.length)
if (contentTypes.total > 1000) {
console.log(
`HI! gatsby-source-plugin isn't setup yet to paginate over 1000 content types (the max we can fetch in one go). Please help out the project and contribute a PR fixing this.`
)
}

const entryList = await Promise.all(
contentTypes.items.map(async contentType => {
Expand All @@ -40,6 +45,7 @@ exports.sourceNodes = async (
try {
entries = await client.getEntries({
content_type: contentTypeId,
limit: 1000,
})
} catch (e) {
console.log(`error fetching entries`, e)
Expand All @@ -48,16 +54,27 @@ exports.sourceNodes = async (
`entries fetched for content type ${contentType.name} (${contentTypeId})`,
entries.items.length
)
if (entries.total > 1000) {
console.log(
`HI! gatsby-source-plugin isn't setup yet to paginate over 1000 entries (the max we can fetch in one go). Please help out the project and contribute a PR fixing this.`
)
}

return entries
})
)

let assets
try {
assets = await client.getAssets()
assets = await client.getAssets({ limit: 1000 })
} catch (e) {
console.log(`error fetching assets`, e)
}
if (assets.total > 1000) {
console.log(
`HI! gatsby-source-plugin isn't setup yet to paginate over 1000 assets (the max we can fetch in one go). Please help out the project and contribute a PR fixing this.`
)
}
console.log(`assets fetched`, assets.items.length)
console.timeEnd(`fetch Contentful data`)

Expand Down
8 changes: 6 additions & 2 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ module.exports = async (program: any) => {
const pluginVersions = flattenedPlugins.map(p => p.version)
const hashes = await Promise.all([
md5File(`package.json`),
Promise.resolve(md5File(`${program.directory}/gatsby-config.js`).catch(() => {})), // ignore as this file isn't required),
Promise.resolve(md5File(`${program.directory}/gatsby-node.js`).catch(() => {})), // ignore as this file isn't required),
Promise.resolve(
md5File(`${program.directory}/gatsby-config.js`).catch(() => {})
), // ignore as this file isn't required),
Promise.resolve(
md5File(`${program.directory}/gatsby-node.js`).catch(() => {})
), // ignore as this file isn't required),
])
const pluginsHash = crypto
.createHash(`md5`)
Expand Down