From 93608019cd52a8a66eece7a585398b3b3955bf7f Mon Sep 17 00:00:00 2001 From: ekzyis Date: Wed, 2 Apr 2025 17:06:13 +0200 Subject: [PATCH] Assert bios in fetch function --- scripts/welcome.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/welcome.js b/scripts/welcome.js index 740eb20a..c2c03b3c 100755 --- a/scripts/welcome.js +++ b/scripts/welcome.js @@ -71,10 +71,10 @@ async function assertSettings () { } } -function fetchRecentBios () { +async function fetchRecentBios () { // fetch all recent bios. we assume here there won't be more than 21 // since the last bio we already included in a post as defined by FETCH_AFTER. - return gql( + const { items: { items: bios } } = await gql( `query NewBios($limit: Limit!) { items(sort: "recent", type: "bios", limit: $limit) { items { @@ -93,9 +93,8 @@ function fetchRecentBios () { } }`, { limit: LIMIT } ) -} -function filterBios (bios) { + // assert that we fetched enough bios const newBios = bios.filter(b => b.id > FETCH_AFTER) if (newBios.length === bios.length) { throw new Error('last bio not found. increase limit') @@ -190,7 +189,6 @@ const util = { assertSettings() .then(fetchRecentBios) - .then(data => filterBios(data.items.items)) .then(populate) .then(printTable) .catch(console.error)