From f111685c5886f3e77edfd3621c98d8ac1b9bcce4 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 24 Nov 2023 20:00:08 +0100 Subject: refactor(services, types): reorganize GraphQL fetchers and data types The Typescript mapped types was useful for autocompletion in fetchers but their are harder to maintain. I think it's better to keep each query close to its fetcher to have a better understanding of the fetched data. So I: * colocate queries with their own fetcher * colocate mutations with their own mutator * remove Typescript mapped types for queries and mutations * move data convertors inside graphql services * rename most of data types and fetchers --- src/pages/thematique/[slug].tsx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/pages/thematique') diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx index b8518c5..a44c98b 100644 --- a/src/pages/thematique/[slug].tsx +++ b/src/pages/thematique/[slug].tsx @@ -17,10 +17,11 @@ import { PageBody, } from '../../components'; import { - getAllThematicsSlugs, - getThematicBySlug, - getThematicsPreview, - getTotalThematics, + convertTaxonomyToPageLink, + fetchAllThematicsSlugs, + fetchThematic, + fetchThematicsCount, + fetchThematicsList, } from '../../services/graphql'; import styles from '../../styles/pages/blog.module.scss'; import type { NextPageWithLayout, PageLink, Thematic } from '../../types'; @@ -28,7 +29,6 @@ import { CONFIG } from '../../utils/config'; import { ROUTES } from '../../utils/constants'; import { getLinksItemData, - getPageLinkFromRawData, getPostsWithUrl, getSchemaJson, getSinglePageSchema, @@ -191,15 +191,13 @@ export const getStaticProps: GetStaticProps = async ({ locale, params, }) => { - const currentThematic = await getThematicBySlug( - (params as ThematicParams).slug - ); - const totalThematics = await getTotalThematics(); - const allThematicsEdges = await getThematicsPreview({ + const currentThematic = await fetchThematic((params as ThematicParams).slug); + const totalThematics = await fetchThematicsCount(); + const allThematicsEdges = await fetchThematicsList({ first: totalThematics, }); const allThematics = allThematicsEdges.edges.map((edge) => - getPageLinkFromRawData(edge.node, 'thematic') + convertTaxonomyToPageLink(edge.node) ); const allThematicsLinks = allThematics.filter( (thematic) => @@ -218,7 +216,7 @@ export const getStaticProps: GetStaticProps = async ({ }; export const getStaticPaths: GetStaticPaths = async () => { - const slugs = await getAllThematicsSlugs(); + const slugs = await fetchAllThematicsSlugs(); const paths = slugs.map((slug) => { return { params: { slug } }; }); -- cgit v1.2.3