aboutsummaryrefslogtreecommitdiffstats
path: root/src/ts/types
diff options
context:
space:
mode:
Diffstat (limited to 'src/ts/types')
-rw-r--r--src/ts/types/graphql/generics.ts25
-rw-r--r--src/ts/types/graphql/mutations.ts61
-rw-r--r--src/ts/types/graphql/queries.ts147
-rw-r--r--src/ts/types/raw-data.ts10
4 files changed, 238 insertions, 5 deletions
diff --git a/src/ts/types/graphql/generics.ts b/src/ts/types/graphql/generics.ts
new file mode 100644
index 0000000..dec5f10
--- /dev/null
+++ b/src/ts/types/graphql/generics.ts
@@ -0,0 +1,25 @@
+export type GraphQLPageInfo = {
+ endCursor: string;
+ hasNextPage: boolean;
+ total: number;
+};
+
+export type GraphQLEdges<T> = {
+ cursor: string;
+ node: T;
+};
+
+export type GraphQLEdgesInput = {
+ after?: string;
+ before?: string;
+ first?: number;
+ last?: number;
+};
+
+export type GraphQLNode<T> = {
+ node: T;
+};
+
+export type GraphQLNodes<T> = {
+ nodes: T[];
+};
diff --git a/src/ts/types/graphql/mutations.ts b/src/ts/types/graphql/mutations.ts
new file mode 100644
index 0000000..10bdbd1
--- /dev/null
+++ b/src/ts/types/graphql/mutations.ts
@@ -0,0 +1,61 @@
+import { sendCommentMutation } from '@services/graphql/comments.mutation';
+import { sendMailMutation } from '@services/graphql/contact.mutation';
+
+//===========================================================================
+// Existing mutations list
+//===========================================================================
+
+export type Mutations = typeof sendMailMutation | typeof sendCommentMutation;
+
+//===========================================================================
+// Mutations response types
+//===========================================================================
+
+export type SendCommentResponse<T> = {
+ createComment: T;
+};
+
+export type SendMailResponse<T> = {
+ sendEmail: T;
+};
+
+export type MutationsResponseMap<T> = {
+ [sendCommentMutation]: SendCommentResponse<T>;
+ [sendMailMutation]: SendMailResponse<T>;
+};
+
+export type Approved = {
+ approved: boolean;
+};
+
+export type SentComment = {
+ clientMutationId: string;
+ success: boolean;
+ comment: Approved | null;
+};
+
+//===========================================================================
+// Mutations input types
+//===========================================================================
+
+export type SendCommentInput = {
+ author: string;
+ authorEmail: string;
+ authorUrl: string;
+ clientMutationId: string;
+ commentOn: number;
+ content: string;
+ parent?: number;
+};
+
+export type SendMailInput = {
+ body: string;
+ clientMutationId: string;
+ replyTo: string;
+ subject: string;
+};
+
+export type MutationsInputMap = {
+ [sendCommentMutation]: SendCommentInput;
+ [sendMailMutation]: SendMailInput;
+};
diff --git a/src/ts/types/graphql/queries.ts b/src/ts/types/graphql/queries.ts
new file mode 100644
index 0000000..cc7b62b
--- /dev/null
+++ b/src/ts/types/graphql/queries.ts
@@ -0,0 +1,147 @@
+import {
+ articleBySlugQuery,
+ articlesCardQuery,
+ articlesEndCursorQuery,
+ articlesQuery,
+ articlesSlugQuery,
+ totalArticlesQuery,
+} from '@services/graphql/articles.query';
+import { commentsQuery } from '@services/graphql/comments.query';
+import {
+ thematicBySlugQuery,
+ thematicsListQuery,
+ thematicsSlugQuery,
+ totalThematicsQuery,
+} from '@services/graphql/thematics.query';
+import {
+ topicBySlugQuery,
+ topicsListQuery,
+ topicsSlugQuery,
+ totalTopicsQuery,
+} from '@services/graphql/topics.query';
+import { Slug } from '../app';
+import { RawComment } from '../raw-data';
+import {
+ GraphQLEdges,
+ GraphQLEdgesInput,
+ GraphQLNodes,
+ GraphQLPageInfo,
+} from './generics';
+
+//===========================================================================
+// Existing queries list
+//===========================================================================
+
+export type Queries =
+ | typeof articlesQuery
+ | typeof articleBySlugQuery
+ | typeof articlesCardQuery
+ | typeof articlesEndCursorQuery
+ | typeof articlesSlugQuery
+ | typeof commentsQuery
+ | typeof thematicBySlugQuery
+ | typeof thematicsListQuery
+ | typeof thematicsSlugQuery
+ | typeof topicBySlugQuery
+ | typeof topicsListQuery
+ | typeof topicsSlugQuery
+ | typeof totalArticlesQuery
+ | typeof totalThematicsQuery
+ | typeof totalTopicsQuery;
+
+//===========================================================================
+// Queries response types
+//===========================================================================
+
+export type ArticleResponse<T> = {
+ post: T;
+};
+
+export type ArticlesResponse<T> = {
+ posts: T;
+};
+
+export type CommentsResponse<T> = {
+ comments: T;
+};
+
+export type ThematicResponse<T> = {
+ thematic: T;
+};
+
+export type ThematicsResponse<T> = {
+ thematics: T;
+};
+
+export type TopicResponse<T> = {
+ topic: T;
+};
+
+export type TopicsResponse<T> = {
+ topics: T;
+};
+
+export type EdgesResponse<T> = {
+ edges: GraphQLEdges<T>[];
+ pageInfo: GraphQLPageInfo;
+};
+
+export type EndCursorResponse = {
+ pageInfo: Pick<GraphQLPageInfo, 'endCursor'>;
+};
+
+export type QueriesResponseMap<T> = {
+ [articleBySlugQuery]: ArticleResponse<T>;
+ [articlesCardQuery]: ArticlesResponse<GraphQLNodes<T>>;
+ [articlesEndCursorQuery]: ArticlesResponse<EndCursorResponse>;
+ [articlesQuery]: ArticlesResponse<EdgesResponse<T>>;
+ [articlesSlugQuery]: ArticlesResponse<EdgesResponse<T>>;
+ [commentsQuery]: CommentsResponse<GraphQLNodes<T>>;
+ [thematicBySlugQuery]: ThematicResponse<T>;
+ [thematicsListQuery]: ThematicsResponse<EdgesResponse<T>>;
+ [thematicsSlugQuery]: ThematicsResponse<EdgesResponse<T>>;
+ [topicBySlugQuery]: TopicResponse<T>;
+ [topicsListQuery]: TopicsResponse<EdgesResponse<T>>;
+ [topicsSlugQuery]: TopicsResponse<EdgesResponse<T>>;
+ [totalArticlesQuery]: ArticlesResponse<T>;
+ [totalThematicsQuery]: ThematicsResponse<T>;
+ [totalTopicsQuery]: TopicsResponse<T>;
+};
+
+//===========================================================================
+// Queries input types
+//===========================================================================
+
+export type QueryEdges = Pick<GraphQLEdgesInput, 'after' | 'first'>;
+
+export type ContentId = {
+ contentId: number;
+};
+
+export type Search = {
+ search?: string;
+};
+
+export type QueriesInputMap = {
+ [articleBySlugQuery]: Slug;
+ [articlesCardQuery]: QueryEdges & Search;
+ [articlesEndCursorQuery]: QueryEdges & Search;
+ [articlesQuery]: QueryEdges & Search;
+ [articlesSlugQuery]: QueryEdges & Search;
+ [commentsQuery]: ContentId;
+ [thematicBySlugQuery]: Slug;
+ [thematicsListQuery]: QueryEdges & Search;
+ [thematicsSlugQuery]: QueryEdges & Search;
+ [topicBySlugQuery]: Slug;
+ [topicsListQuery]: QueryEdges & Search;
+ [topicsSlugQuery]: QueryEdges & Search;
+ [totalArticlesQuery]: Search;
+ [totalThematicsQuery]: null;
+ [totalTopicsQuery]: null;
+};
+
+export type CommentPage = {
+ comments: RawComment[];
+ hasNextPage: boolean;
+ endCursor: string;
+};
diff --git a/src/ts/types/raw-data.ts b/src/ts/types/raw-data.ts
index dc3db90..ae7f7c6 100644
--- a/src/ts/types/raw-data.ts
+++ b/src/ts/types/raw-data.ts
@@ -2,8 +2,8 @@
* Types for raw data coming from GraphQL API.
*/
-import { NodeResponse, PageInfo } from '@services/graphql/api';
import { ContentKind } from './app';
+import { GraphQLNode, GraphQLPageInfo } from './graphql/generics';
export type ACFPosts = {
postsInThematic?: RawThematicPreview[];
@@ -37,7 +37,7 @@ export type RawAuthor<T extends ContentKind> = {
export type RawComment = {
approved: boolean;
- author: NodeResponse<RawAuthor<'comment'>>;
+ author: GraphQLNode<RawAuthor<'comment'>>;
content: string;
databaseId: number;
date: string;
@@ -65,11 +65,11 @@ export type RawArticlePreview = Pick<
>;
export type RawPage = {
- author?: NodeResponse<RawAuthor<'page'>>;
+ author?: GraphQLNode<RawAuthor<'page'>>;
contentParts: ContentParts;
databaseId: number;
date: string;
- featuredImage: NodeResponse<RawCover> | null;
+ featuredImage: GraphQLNode<RawCover> | null;
info: Info;
modified: string;
seo?: RawSEO;
@@ -101,5 +101,5 @@ export type RawTopicPreview = Pick<
>;
export type TotalItems = {
- pageInfo: Pick<PageInfo, 'total'>;
+ pageInfo: Pick<GraphQLPageInfo, 'total'>;
};