From d8a5a8a8e017d058fa42a2b5be6a0c6c8c841242 Mon Sep 17 00:00:00 2001 From: Alex Moon Date: Mon, 6 Apr 2020 03:26:14 +0000 Subject: [PATCH 1/4] fix: #22703 missing data in serialize funciton --- packages/gatsby-plugin-sitemap/src/internals.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-plugin-sitemap/src/internals.js b/packages/gatsby-plugin-sitemap/src/internals.js index 8e61b4afec0cc..e7f891e1a091d 100644 --- a/packages/gatsby-plugin-sitemap/src/internals.js +++ b/packages/gatsby-plugin-sitemap/src/internals.js @@ -14,13 +14,16 @@ export function filterQuery( pathPrefix, resolveSiteUrl = defaultOptions.resolveSiteUrl ) { - const { errors, data } = results + const { + errors, + data: { allSitePage, site, ...otherData }, + } = results if (errors) { throw new Error(errors.join(`, `)) } - let { allPages, originalType } = getNodes(data.allSitePage) + let { allPages, originalType } = getNodes(allSitePage) // Removing excluded paths allPages = allPages.filter( @@ -41,7 +44,7 @@ export function filterQuery( // siteUrl Validation - let siteUrl = resolveSiteUrl(data) + let siteUrl = resolveSiteUrl(site) if (!siteUrl || siteUrl.trim().length == 0) { throw new Error( @@ -62,6 +65,7 @@ export function filterQuery( }), }, site: { siteMetadata: { siteUrl } }, + ...otherData, } } @@ -100,7 +104,7 @@ export const defaultOptions = { } }) }, - resolveSiteUrl: data => data.site.siteMetadata.siteUrl, + resolveSiteUrl: data => data.siteMetadata.siteUrl, } function getNodes(results) { From 164419004a1ef7a3a192a53e5dcd93093da5fb9c Mon Sep 17 00:00:00 2001 From: Alex Moon Date: Mon, 6 Apr 2020 03:36:17 +0000 Subject: [PATCH 2/4] fix: revert a couple changes for url resolution to not change and get whole query --- packages/gatsby-plugin-sitemap/src/internals.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/gatsby-plugin-sitemap/src/internals.js b/packages/gatsby-plugin-sitemap/src/internals.js index e7f891e1a091d..8a48ab567252b 100644 --- a/packages/gatsby-plugin-sitemap/src/internals.js +++ b/packages/gatsby-plugin-sitemap/src/internals.js @@ -14,15 +14,16 @@ export function filterQuery( pathPrefix, resolveSiteUrl = defaultOptions.resolveSiteUrl ) { - const { - errors, - data: { allSitePage, site, ...otherData }, - } = results + const { errors, data } = results if (errors) { throw new Error(errors.join(`, `)) } + // site shouldn't be included in "otherData but isn't needed either." + // eslint-disable-next-line no-unused-vars + const { allSitePage, site, ...otherData } = data + let { allPages, originalType } = getNodes(allSitePage) // Removing excluded paths @@ -44,7 +45,7 @@ export function filterQuery( // siteUrl Validation - let siteUrl = resolveSiteUrl(site) + let siteUrl = resolveSiteUrl(data) if (!siteUrl || siteUrl.trim().length == 0) { throw new Error( @@ -104,7 +105,7 @@ export const defaultOptions = { } }) }, - resolveSiteUrl: data => data.siteMetadata.siteUrl, + resolveSiteUrl: data => data.site.siteMetadata.siteUrl, } function getNodes(results) { From df6ee4db6ab1a13fbb5daaa3006a8b7995c7697f Mon Sep 17 00:00:00 2001 From: Alex Moon Date: Mon, 6 Apr 2020 03:39:44 +0000 Subject: [PATCH 3/4] refactor: move otherData spread to top so site is overritten by propper url if needed --- packages/gatsby-plugin-sitemap/src/internals.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-plugin-sitemap/src/internals.js b/packages/gatsby-plugin-sitemap/src/internals.js index 8a48ab567252b..7b5a8356a8425 100644 --- a/packages/gatsby-plugin-sitemap/src/internals.js +++ b/packages/gatsby-plugin-sitemap/src/internals.js @@ -20,9 +20,7 @@ export function filterQuery( throw new Error(errors.join(`, `)) } - // site shouldn't be included in "otherData but isn't needed either." - // eslint-disable-next-line no-unused-vars - const { allSitePage, site, ...otherData } = data + const { allSitePage, ...otherData } = data let { allPages, originalType } = getNodes(allSitePage) @@ -57,6 +55,7 @@ export function filterQuery( siteUrl = withoutTrailingSlash(siteUrl) return { + ...otherData, allSitePage: { [originalType]: originalType === `nodes` @@ -66,7 +65,6 @@ export function filterQuery( }), }, site: { siteMetadata: { siteUrl } }, - ...otherData, } } From 39c6ad41549204201b135b54119b0fec282d2a5b Mon Sep 17 00:00:00 2001 From: Alex Moon Date: Fri, 10 Apr 2020 05:44:13 +0000 Subject: [PATCH 4/4] test: add test to confirm non standard data is passed --- .../gatsby-plugin-sitemap/src/__tests__/internals.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/gatsby-plugin-sitemap/src/__tests__/internals.js b/packages/gatsby-plugin-sitemap/src/__tests__/internals.js index 8b047261d2c74..7a8b5652f25be 100644 --- a/packages/gatsby-plugin-sitemap/src/__tests__/internals.js +++ b/packages/gatsby-plugin-sitemap/src/__tests__/internals.js @@ -137,6 +137,16 @@ describe(`results using non default alternatives`, () => { }, ], }, + otherData: { + nodes: [ + { + name: `test`, + }, + { + name: `test 2`, + }, + ], + }, }, } } @@ -161,5 +171,6 @@ describe(`results using non default alternatives`, () => { const queryRecords = filterQuery(results, [], ``, customSiteResolver) expect(queryRecords.site.siteMetadata.siteUrl).toEqual(customUrl) + expect(queryRecords).toHaveProperty(`otherData`) }) })