From 688376b9e4a96e4bd9d49034874aab3b51e734eb Mon Sep 17 00:00:00 2001 From: Joe Stramel Date: Thu, 4 Nov 2021 17:00:39 -0400 Subject: [PATCH] searcParams missing from urls (#33861) - Fix issue where params such as api-key are not added to the url (cherry picked from commit c9a35ed030050cd957674de72da8c561ac40bea0) --- packages/gatsby-source-drupal/src/gatsby-node.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/gatsby-source-drupal/src/gatsby-node.js b/packages/gatsby-source-drupal/src/gatsby-node.js index ed65d5419dfa9..d3ae889019ab4 100644 --- a/packages/gatsby-source-drupal/src/gatsby-node.js +++ b/packages/gatsby-source-drupal/src/gatsby-node.js @@ -61,6 +61,21 @@ async function worker([url, options]) { } } + if (typeof options.searchParams === `object`) { + url = new URL(url) + const searchParams = new URLSearchParams(options.searchParams) + const searchKeys = Array.from(searchParams.keys()) + searchKeys.forEach(searchKey => { + // Only add search params to url if it has not already been + // added. + if (!url.searchParams.has(searchKey)) { + url.searchParams.set(searchKey, searchParams.get(searchKey)) + } + }) + url = url.toString() + } + delete options.searchParams + const response = await got(url, { agent, cache: false, @@ -467,6 +482,7 @@ ${JSON.stringify(webhookBody, null, 4)}` username: basicAuth.username, password: basicAuth.password, headers, + searchParams: params, responseType: `json`, parentSpan: fullFetchSpan, },