From f111685c5886f3e77edfd3621c98d8ac1b9bcce4 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
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/index.tsx | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

(limited to 'src/pages/index.tsx')

diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 56de5b5..7bd8aec 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -26,9 +26,12 @@ import {
 } from '../components';
 import { mdxComponents } from '../components/mdx';
 import HomePageContent from '../content/pages/homepage.mdx';
-import { getArticlesCard } from '../services/graphql';
+import {
+  convertRecentPostToRecentArticle,
+  fetchRecentPosts,
+} from '../services/graphql';
 import styles from '../styles/pages/home.module.scss';
-import type { ArticleCard, NextPageWithLayout } from '../types';
+import type { NextPageWithLayout, RecentArticle } from '../types';
 import { CONFIG } from '../utils/config';
 import { PERSONAL_LINKS, ROUTES } from '../utils/constants';
 import { getSchemaJson, getWebPageSchema } from '../utils/helpers';
@@ -229,7 +232,7 @@ const HomePageSection: FC<PageSectionProps> = ({
 );
 
 type HomeProps = {
-  recentPosts: ArticleCard[];
+  recentPosts: RecentArticle[];
   translation?: Messages;
 };
 
@@ -277,7 +280,7 @@ const HomePage: NextPageWithLayout<HomeProps> = ({ recentPosts }) => {
                   hasBorderedValues
                   isCentered
                   label={publicationDate}
-                  value={<Time date={post.dates.publication} />}
+                  value={<Time date={post.publicationDate} />}
                 />
               </CardMeta>
             }
@@ -365,11 +368,13 @@ HomePage.getLayout = (page) => getLayout(page, { isHome: true });
 
 export const getStaticProps: GetStaticProps<HomeProps> = async ({ locale }) => {
   const translation = await loadTranslation(locale);
-  const recentPosts = await getArticlesCard({ first: 3 });
+  const recentPosts = await fetchRecentPosts({ first: 3 });
 
   return {
     props: {
-      recentPosts,
+      recentPosts: recentPosts.edges.map((edge) =>
+        convertRecentPostToRecentArticle(edge.node)
+      ),
       translation,
     },
   };
-- 
cgit v1.2.3

