diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-24 20:00:08 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-27 14:47:51 +0100 |
| commit | f111685c5886f3e77edfd3621c98d8ac1b9bcce4 (patch) | |
| tree | 62a541fe3afeb64bf745443706fbfb02e96c5230 /src/pages/sujet | |
| parent | bee515641cb144be9a855ff2cac258d2fedab21d (diff) | |
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
Diffstat (limited to 'src/pages/sujet')
| -rw-r--r-- | src/pages/sujet/[slug].tsx | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx index 30adec3..aed7ea9 100644 --- a/src/pages/sujet/[slug].tsx +++ b/src/pages/sujet/[slug].tsx @@ -18,10 +18,11 @@ import { PageBody, } from '../../components'; import { - getAllTopicsSlugs, - getTopicBySlug, - getTopicsPreview, - getTotalTopics, + convertTaxonomyToPageLink, + fetchAllTopicsSlugs, + fetchTopic, + fetchTopicsCount, + fetchTopicsList, } from '../../services/graphql'; import styles from '../../styles/pages/blog.module.scss'; import type { NextPageWithLayout, PageLink, Topic } from '../../types'; @@ -29,7 +30,6 @@ import { CONFIG } from '../../utils/config'; import { ROUTES } from '../../utils/constants'; import { getLinksItemData, - getPageLinkFromRawData, getPostsWithUrl, getSchemaJson, getSinglePageSchema, @@ -208,13 +208,13 @@ export const getStaticProps: GetStaticProps<TopicPageProps> = async ({ locale, params, }) => { - const currentTopic = await getTopicBySlug((params as TopicParams).slug); - const totalTopics = await getTotalTopics(); - const allTopicsEdges = await getTopicsPreview({ + const currentTopic = await fetchTopic((params as TopicParams).slug); + const totalTopics = await fetchTopicsCount(); + const allTopicsEdges = await fetchTopicsList({ first: totalTopics, }); const allTopics = allTopicsEdges.edges.map((edge) => - getPageLinkFromRawData(edge.node, 'topic') + convertTaxonomyToPageLink(edge.node) ); const topicsLinks = allTopics.filter( (topic) => topic.url !== `${ROUTES.TOPICS}/${(params as TopicParams).slug}` @@ -231,7 +231,7 @@ export const getStaticProps: GetStaticProps<TopicPageProps> = async ({ }; export const getStaticPaths: GetStaticPaths = async () => { - const slugs = await getAllTopicsSlugs(); + const slugs = await fetchAllTopicsSlugs(); const paths = slugs.map((slug) => { return { params: { slug } }; }); |
