aboutsummaryrefslogtreecommitdiffstats
path: root/src/services
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-04-29 12:13:34 +0200
committerArmand Philippot <git@armandphilippot.com>2022-04-29 18:30:05 +0200
commit7e16f500cb7bc0cfd8bafbf6bb1555704f771231 (patch)
treebfc2b4a475cb06a787e2c4bdf284165644e82952 /src/services
parent5324664e87bedfaa01ba62c0c847ef5b861e69b3 (diff)
chore: remove old pages, components, helpers and types
Since I'm using new components, I will also rewrite the GraphQL queries so it is easier to start from scratch.
Diffstat (limited to 'src/services')
-rw-r--r--src/services/graphql/api.ts25
-rw-r--r--src/services/graphql/mutations.ts82
-rw-r--r--src/services/graphql/queries.ts535
3 files changed, 0 insertions, 642 deletions
diff --git a/src/services/graphql/api.ts b/src/services/graphql/api.ts
deleted file mode 100644
index a5be026..0000000
--- a/src/services/graphql/api.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { RequestType, VariablesType } from '@ts/types/app';
-import { settings } from '@utils/config';
-import { GraphQLClient } from 'graphql-request';
-
-export const getGraphQLClient = (): GraphQLClient => {
- const apiUrl = settings.api.url;
-
- if (!apiUrl) throw new Error('API URL not defined.');
-
- return new GraphQLClient(apiUrl);
-};
-
-export const fetchApi = async <T extends RequestType>(
- query: string,
- variables: VariablesType<T>
-): Promise<T> => {
- const client = getGraphQLClient();
-
- try {
- return await client.request(query, variables);
- } catch (error) {
- console.error(error, undefined, 2);
- process.exit(1);
- }
-};
diff --git a/src/services/graphql/mutations.ts b/src/services/graphql/mutations.ts
deleted file mode 100644
index c697835..0000000
--- a/src/services/graphql/mutations.ts
+++ /dev/null
@@ -1,82 +0,0 @@
-import { CommentData, CreateComment, CreatedComment } from '@ts/types/comments';
-import { ContactData, SendEmail } from '@ts/types/contact';
-import { gql } from 'graphql-request';
-import { fetchApi } from './api';
-
-//==============================================================================
-// Comment mutation
-//==============================================================================
-
-export const createComment = async (
- data: CommentData
-): Promise<CreatedComment> => {
- const mutation = gql`
- mutation CreateComment(
- $author: String!
- $authorEmail: String!
- $authorUrl: String!
- $content: String!
- $parent: ID!
- $commentOn: Int!
- $mutationId: String!
- ) {
- createComment(
- input: {
- author: $author
- authorEmail: $authorEmail
- authorUrl: $authorUrl
- content: $content
- parent: $parent
- commentOn: $commentOn
- clientMutationId: $mutationId
- }
- ) {
- clientMutationId
- success
- comment {
- approved
- }
- }
- }
- `;
-
- const variables = { ...data };
- const response = await fetchApi<CreateComment>(mutation, variables);
-
- return response.createComment;
-};
-
-//==============================================================================
-// Contact mutation
-//==============================================================================
-
-export const sendMail = async (data: ContactData) => {
- const mutation = gql`
- mutation SendEmail(
- $subject: String!
- $body: String!
- $replyTo: String!
- $mutationId: String!
- ) {
- sendEmail(
- input: {
- clientMutationId: $mutationId
- body: $body
- replyTo: $replyTo
- subject: $subject
- }
- ) {
- clientMutationId
- message
- sent
- origin
- replyTo
- to
- }
- }
- `;
-
- const variables = { ...data };
- const response = await fetchApi<SendEmail>(mutation, variables);
- return response.sendEmail;
-};
diff --git a/src/services/graphql/queries.ts b/src/services/graphql/queries.ts
deleted file mode 100644
index 9caf62b..0000000
--- a/src/services/graphql/queries.ts
+++ /dev/null
@@ -1,535 +0,0 @@
-import { Slug } from '@ts/types/app';
-import { Article, PostBy, TotalArticles } from '@ts/types/articles';
-import {
- AllPostsSlug,
- LastPostCursor,
- PostsList,
- RawPostsList,
-} from '@ts/types/blog';
-import { Comment, CommentsByPostId } from '@ts/types/comments';
-import {
- AllTopics,
- AllTopicsSlug,
- AllThematics,
- AllThematicsSlug,
- Topic,
- TopicBy,
- TopicPreview,
- Thematic,
- ThematicBy,
- ThematicPreview,
-} from '@ts/types/taxonomies';
-import {
- getFormattedPost,
- getFormattedPostPreview,
- getFormattedTopic,
- getFormattedThematic,
- getFormattedComments,
- buildCommentsTree,
-} from '@utils/helpers/format';
-import { gql } from 'graphql-request';
-import { fetchApi } from './api';
-
-//==============================================================================
-// Posts list queries
-//==============================================================================
-
-export const getPostsTotal = async (): Promise<number> => {
- const query = gql`
- query PostsTotal {
- posts {
- pageInfo {
- total
- }
- }
- }
- `;
-
- const response = await fetchApi<TotalArticles>(query, null);
- return response.posts.pageInfo.total;
-};
-
-export const getPublishedPosts = async ({
- first = 10,
- after = '',
- searchQuery = '',
-}: {
- first: number;
- after?: string;
- searchQuery?: string;
-}): Promise<PostsList> => {
- const query = gql`
- query AllPublishedPosts($first: Int, $after: String, $searchQuery: String) {
- posts(
- after: $after
- first: $first
- where: {
- status: PUBLISH
- orderby: { field: DATE, order: DESC }
- search: $searchQuery
- }
- ) {
- edges {
- cursor
- node {
- acfPosts {
- postsInTopic {
- ... on Topic {
- databaseId
- featuredImage {
- node {
- altText
- sourceUrl
- title
- }
- }
- id
- slug
- title
- }
- }
- postsInThematic {
- ... on Thematic {
- databaseId
- id
- slug
- title
- }
- }
- }
- commentCount
- contentParts {
- beforeMore
- }
- date
- featuredImage {
- node {
- altText
- sourceUrl
- title
- }
- }
- id
- info {
- readingTime
- wordsCount
- }
- databaseId
- modified
- slug
- title
- }
- }
- pageInfo {
- endCursor
- hasNextPage
- total
- }
- }
- }
- `;
-
- const variables = { first, after, searchQuery };
- const response = await fetchApi<RawPostsList>(query, variables);
- const formattedPosts = response.posts.edges.map((post) => {
- return getFormattedPostPreview(post.node);
- });
-
- return {
- posts: formattedPosts,
- pageInfo: response.posts.pageInfo,
- };
-};
-
-export const getAllPostsSlug = async (): Promise<Slug[]> => {
- // 10 000 is an arbitrary number that I use for small websites.
- const query = gql`
- query AllPostsSlug {
- posts(first: 10000) {
- nodes {
- slug
- }
- }
- }
- `;
-
- const response = await fetchApi<AllPostsSlug>(query, null);
- return response.posts.nodes;
-};
-
-//==============================================================================
-// Single Post query
-//==============================================================================
-
-export const getPostBySlug = async (slug: string): Promise<Article> => {
- const query = gql`
- query PostBySlug($slug: ID!) {
- post(id: $slug, idType: SLUG) {
- acfPosts {
- postsInTopic {
- ... on Topic {
- id
- featuredImage {
- node {
- altText
- sourceUrl
- title
- }
- }
- slug
- title
- }
- }
- postsInThematic {
- ... on Thematic {
- id
- slug
- title
- }
- }
- }
- author {
- node {
- firstName
- lastName
- name
- }
- }
- commentCount
- contentParts {
- afterMore
- beforeMore
- }
- databaseId
- date
- featuredImage {
- node {
- altText
- sourceUrl
- title
- }
- }
- id
- info {
- readingTime
- wordsCount
- }
- modified
- seo {
- metaDesc
- title
- }
- title
- }
- }
- `;
- const variables = { slug };
- const response = await fetchApi<PostBy>(query, variables);
-
- return getFormattedPost(response.post);
-};
-
-//==============================================================================
-// Comments query
-//==============================================================================
-
-export const getCommentsByPostId = async (id: number): Promise<Comment[]> => {
- const query = gql`
- query PostComments($id: ID!) {
- comments(where: { contentId: $id, order: ASC, orderby: COMMENT_DATE }) {
- nodes {
- approved
- author {
- node {
- databaseId
- gravatarUrl
- name
- url
- }
- }
- content
- databaseId
- date
- parentDatabaseId
- }
- }
- }
- `;
-
- const variables = { id };
- const response = await fetchApi<CommentsByPostId>(query, variables);
- const formattedComments = getFormattedComments(response.comments.nodes);
-
- return buildCommentsTree(formattedComments);
-};
-
-//==============================================================================
-// Topic query
-//==============================================================================
-
-export const getTopicBySlug = async (slug: string): Promise<Topic> => {
- const query = gql`
- query TopicBySlug($slug: ID!) {
- topic(id: $slug, idType: SLUG) {
- acfTopics {
- officialWebsite
- postsInTopic {
- ... on Post {
- acfPosts {
- postsInTopic {
- ... on Topic {
- databaseId
- featuredImage {
- node {
- altText
- sourceUrl
- title
- }
- }
- id
- slug
- title
- }
- }
- postsInThematic {
- ... on Thematic {
- databaseId
- id
- slug
- title
- }
- }
- }
- id
- info {
- readingTime
- wordsCount
- }
- commentCount
- contentParts {
- beforeMore
- }
- databaseId
- date
- featuredImage {
- node {
- altText
- sourceUrl
- title
- }
- }
- modified
- slug
- title
- }
- }
- }
- contentParts {
- afterMore
- beforeMore
- }
- databaseId
- date
- featuredImage {
- node {
- altText
- sourceUrl
- title
- }
- }
- id
- info {
- readingTime
- wordsCount
- }
- modified
- seo {
- metaDesc
- title
- }
- title
- }
- }
- `;
- const variables = { slug };
- const response = await fetchApi<TopicBy>(query, variables);
-
- return getFormattedTopic(response.topic);
-};
-
-export const getAllTopicsSlug = async (): Promise<Slug[]> => {
- // 10 000 is an arbitrary number that I use for small websites.
- const query = gql`
- query AllTopicsSlug {
- topics(first: 10000) {
- nodes {
- slug
- }
- }
- }
- `;
- const response = await fetchApi<AllTopicsSlug>(query, null);
- return response.topics.nodes;
-};
-
-export const getAllTopics = async (): Promise<TopicPreview[]> => {
- // 10 000 is an arbitrary number that I use for small websites.
- const query = gql`
- query AllTopics {
- topics(first: 10000, where: { orderby: { field: TITLE, order: ASC } }) {
- nodes {
- databaseId
- slug
- title
- }
- }
- }
- `;
-
- const response = await fetchApi<AllTopics>(query, null);
- return response.topics.nodes;
-};
-
-//==============================================================================
-// Thematic query
-//==============================================================================
-
-export const getThematicBySlug = async (slug: string): Promise<Thematic> => {
- const query = gql`
- query ThematicBySlug($slug: ID!) {
- thematic(id: $slug, idType: SLUG) {
- acfThematics {
- postsInThematic {
- ... on Post {
- acfPosts {
- postsInTopic {
- ... on Topic {
- databaseId
- featuredImage {
- node {
- altText
- sourceUrl
- title
- }
- }
- id
- slug
- title
- }
- }
- postsInThematic {
- ... on Thematic {
- databaseId
- id
- slug
- title
- }
- }
- }
- id
- info {
- readingTime
- wordsCount
- }
- commentCount
- contentParts {
- beforeMore
- }
- databaseId
- date
- featuredImage {
- node {
- altText
- sourceUrl
- title
- }
- }
- modified
- slug
- title
- }
- }
- }
- contentParts {
- afterMore
- beforeMore
- }
- databaseId
- date
- id
- info {
- readingTime
- wordsCount
- }
- modified
- seo {
- metaDesc
- title
- }
- title
- }
- }
- `;
- const variables = { slug };
- const response = await fetchApi<ThematicBy>(query, variables);
-
- return getFormattedThematic(response.thematic);
-};
-
-export const getAllThematicsSlug = async (): Promise<Slug[]> => {
- // 10 000 is an arbitrary number that I use for small websites.
- const query = gql`
- query AllThematicsSlug {
- thematics(first: 10000) {
- nodes {
- slug
- }
- }
- }
- `;
- const response = await fetchApi<AllThematicsSlug>(query, null);
- return response.thematics.nodes;
-};
-
-export const getAllThematics = async (): Promise<ThematicPreview[]> => {
- // 10 000 is an arbitrary number that I use for small websites.
- const query = gql`
- query AllThematics {
- thematics(
- first: 10000
- where: { orderby: { field: TITLE, order: ASC } }
- ) {
- nodes {
- databaseId
- slug
- title
- }
- }
- }
- `;
-
- const response = await fetchApi<AllThematics>(query, null);
- return response.thematics.nodes;
-};
-
-export const getEndCursor = async ({
- first = 10,
-}: {
- first: number;
-}): Promise<string> => {
- const query = gql`
- query EndCursorAfter($first: Int) {
- posts(first: $first) {
- pageInfo {
- hasNextPage
- endCursor
- }
- }
- }
- `;
-
- const variables = { first };
- const response = await fetchApi<LastPostCursor>(query, variables);
-
- return response.posts.pageInfo.endCursor;
-};