aboutsummaryrefslogtreecommitdiffstats
path: root/src/services
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-01-04 13:35:25 +0100
committerArmand Philippot <git@armandphilippot.com>2022-01-04 13:35:25 +0100
commitd53d375d09dd86a85ffb249de1c0cc7c3b3438bc (patch)
tree827e02f739a542e674e5d447f46ee97096f02cd7 /src/services
parentab5e5f4bdf40b5bc1ccf82dc1b4aca94d5171ec3 (diff)
refactor: avoid useless assignement before return statement
Diffstat (limited to 'src/services')
-rw-r--r--src/services/graphql/api.ts7
-rw-r--r--src/services/graphql/queries.ts17
2 files changed, 7 insertions, 17 deletions
diff --git a/src/services/graphql/api.ts b/src/services/graphql/api.ts
index de8024f..33cc89a 100644
--- a/src/services/graphql/api.ts
+++ b/src/services/graphql/api.ts
@@ -6,9 +6,7 @@ export const getGraphQLClient = (): GraphQLClient => {
if (!apiUrl) throw new Error('API URL not defined.');
- const graphQLClient = new GraphQLClient(apiUrl);
-
- return graphQLClient;
+ return new GraphQLClient(apiUrl);
};
export const fetchApi = async <T extends RequestType>(
@@ -18,8 +16,7 @@ export const fetchApi = async <T extends RequestType>(
const client = getGraphQLClient();
try {
- const response = await client.request(query, variables);
- return response;
+ return await client.request(query, variables);
} catch (error) {
console.error(error, undefined, 2);
process.exit(1);
diff --git a/src/services/graphql/queries.ts b/src/services/graphql/queries.ts
index 1cbb616..afc9f69 100644
--- a/src/services/graphql/queries.ts
+++ b/src/services/graphql/queries.ts
@@ -100,17 +100,13 @@ export const getPublishedPosts = async ({
const variables = { first, after, searchQuery };
const response = await fetchApi<RawPostsList>(query, variables);
const formattedPosts = response.posts.edges.map((post) => {
- const formattedPost = getFormattedPostPreview(post.node);
-
- return formattedPost;
+ return getFormattedPostPreview(post.node);
});
- const postsList = {
+ return {
posts: formattedPosts,
pageInfo: response.posts.pageInfo,
};
-
- return postsList;
};
export const getAllPostsSlug = async (): Promise<Slug[]> => {
@@ -226,9 +222,8 @@ export const getPostBySlug = async (slug: string): Promise<Article> => {
`;
const variables = { slug };
const response = await fetchApi<PostBy>(query, variables);
- const post = getFormattedPost(response.postBy);
- return post;
+ return getFormattedPost(response.postBy);
};
//==============================================================================
@@ -328,9 +323,8 @@ export const getSubjectBySlug = async (slug: string): Promise<Subject> => {
`;
const variables = { slug };
const response = await fetchApi<SubjectBy>(query, variables);
- const subject = getFormattedSubject(response.subjectBy);
- return subject;
+ return getFormattedSubject(response.subjectBy);
};
export const getAllSubjectsSlug = async (): Promise<Slug[]> => {
@@ -437,9 +431,8 @@ export const getThematicBySlug = async (slug: string): Promise<Thematic> => {
`;
const variables = { slug };
const response = await fetchApi<ThematicBy>(query, variables);
- const thematic = getFormattedThematic(response.thematicBy);
- return thematic;
+ return getFormattedThematic(response.thematicBy);
};
export const getAllThematicsSlug = async (): Promise<Slug[]> => {