From cc52a77ffcfe6862ef70c1507b7a95493602984a Mon Sep 17 00:00:00 2001 From: Mehul Mathur Date: Wed, 11 Sep 2024 20:07:38 +0000 Subject: [PATCH] testing --- projects/mehulmathur16/src/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/projects/mehulmathur16/src/index.ts b/projects/mehulmathur16/src/index.ts index 379a8ad..9756e1d 100644 --- a/projects/mehulmathur16/src/index.ts +++ b/projects/mehulmathur16/src/index.ts @@ -16,8 +16,8 @@ server.register(mercurius, { let cache = { usersList: null, postsList: null, - postMap: {}, - userMap: {} + postMap: {} as any, + userMap: {} as any }; const userDataLoader = new DataLoader(async function (ids: any) { @@ -38,7 +38,11 @@ server.register(mercurius, { const posts = await Promise.all( ids.map(async (id: any) => { try { - const response = await axiosInstance.get(`/posts/${id}`,); + if (cache.postMap[id]) { + return cache.postMap[id] + } + const response = await axiosInstance.get(`/posts/${id}`); + cache.postMap[id] = response.data; return response.data; } catch (error: any) { return new Error(`Failed to fetch post with id ${id}: ${error.message}`);