Skip to content

Commit

Permalink
use new browser-based URL parser
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Aug 23, 2021
1 parent d31c5f9 commit 3cf6797
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const _ = require(`lodash`)
const urlJoin = require(`url-join`)
import HttpAgent from "agentkeepalive"
// const http2wrapper = require(`http2-wrapper`)
const url = require(`url`)
const querystring = require(`querystring`)

const { HttpsAgent } = HttpAgent

Expand Down Expand Up @@ -391,21 +389,13 @@ exports.sourceNodes = async (
`queueing ${requestsCount} API requests for type ${d.body.data[0].type} which has ${d.body.meta.count} entities.`
)
if (d.body.links.next?.href) {
const parsedUrl = url.parse(d.body.links.next?.href)
const parsedQueryString = querystring.parse(parsedUrl.query)
await Promise.all(
_.range(requestsCount).map(pageOffset => {
pageOffset += 1
// Construct query string.
const newQuerystring = {
...parsedQueryString,
"page[offset]": pageOffset * 50,
}
const newUrl = url.format({
...parsedUrl,
search: querystring.stringify(newQuerystring),
})
return getNext(newUrl)
// Construct URL with new pageOffset.
const newUrl = new URL(d.body.links.next.href)
newUrl.searchParams.set(`page[offset]`, pageOffset * 50)
return getNext(newUrl.toString())
})
)
}
Expand Down

0 comments on commit 3cf6797

Please sign in to comment.