From 0420dc30a4c23ef04858b568f4903bd4d49d4ee8 Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Wed, 22 Feb 2023 06:12:58 +0100 Subject: [PATCH] Add revalidation for weapon stories and groups --- .../revalidationGetWeaponGroup.graphql | 15 +++++++++ src/pages/api/revalidate.ts | 32 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/graphql/operations/revalidation/revalidationGetWeaponGroup.graphql diff --git a/src/graphql/operations/revalidation/revalidationGetWeaponGroup.graphql b/src/graphql/operations/revalidation/revalidationGetWeaponGroup.graphql new file mode 100644 index 0000000..e051672 --- /dev/null +++ b/src/graphql/operations/revalidation/revalidationGetWeaponGroup.graphql @@ -0,0 +1,15 @@ +query revalidationGetWeaponGroup($id: ID) { + weaponStoryGroup(id: $id) { + data { + attributes { + weapons(pagination: { limit: -1 }) { + data { + attributes { + slug + } + } + } + } + } + } +} diff --git a/src/pages/api/revalidate.ts b/src/pages/api/revalidate.ts index 36858d2..e4d42a7 100644 --- a/src/pages/api/revalidate.ts +++ b/src/pages/api/revalidate.ts @@ -28,6 +28,8 @@ type RequestProps = | StrapiPostContent | StrapiRangedContent | StrapiVideo + | StrapiWeaponGroup + | StrapiWeaponStory | StrapiWebsiteInterface | StrapiWiki; @@ -36,6 +38,21 @@ interface CustomRequest { path: string; } +interface StrapiWeaponStory extends StrapiEvent { + model: "weapon-story"; + entry: { + slug: string; + }; +} + +interface StrapiWeaponGroup extends StrapiEvent { + model: "weapon-story-group"; + entry: { + id: string; + slug: string; + }; +} + interface StrapiRangedContent extends StrapiEvent { event: CRUDEvents; model: "ranged-content"; @@ -311,6 +328,21 @@ const Revalidate = async ( break; } + case "weapon-story": { + paths.push(`/wiki/weapons/${body.entry.slug}`); + break; + } + + case "weapon-story-group": { + const group = await sdk.revalidationGetWeaponGroup({ + id: body.entry.id, + }); + filterHasAttributes(group.weaponStoryGroup?.data?.attributes?.weapons?.data, [ + "attributes.slug", + ] as const).forEach((weapon) => paths.push(`/wiki/weapons/${weapon.attributes.slug}`)); + break; + } + case "custom": { paths.push(`${body.path}`); break;