-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphcms.tsx
100 lines (92 loc) · 1.85 KB
/
graphcms.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { GraphQLClient, gql } from "graphql-request";
export interface Image {
url: string;
}
export interface Post {
title: string;
createdAt: string;
slug: string;
author: string;
id: number;
description: string;
publishedAt: string;
updatedAt: string;
content: {
html: string;
};
shortDescription: string;
image: Image;
featuredPost: boolean;
}
export interface Project {
title: string;
category: string;
description: string;
heroDescription: string;
shortDescription: string;
createdAt: string;
image: Image;
slug: string;
content: {
html: string;
};
client: string;
service: string;
deliverable: string;
keywords: string[];
}
export const graphcms = new GraphQLClient(
"https://api-eu-central-1-shared-euc1-02.hygraph.com/v2/cljaggjro2abl01ue45ggesph/master"
);
export const getProjects = async (val: boolean): Promise<Project[]> => {
const QUERY = gql`
query {
projects {
title
category
description
heroDescription
slug
shortDescription
image {
url
}
client
service
deliverable
keywords
content {
html
}
}
}
`;
const { projects } = await graphcms.request<{ projects: Project[] }>(QUERY);
if (val === true) {
return projects.slice(0, 3);
} else return projects;
};
export const getPosts = async (val: boolean): Promise<Post[]> => {
const QUERY = gql`
query {
posts {
createdAt
id
publishedAt
image {
url
}
slug
shortDescription
description
title
updatedAt
featuredPost
}
}
`;
const { posts } = await graphcms.request<{ posts: Post[] }>(QUERY);
if (val === true) {
return posts.slice(0, 4);
} else return posts;
};