Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulmathur16 committed Sep 11, 2024
1 parent 4b7d61e commit cc52a77
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions projects/mehulmathur16/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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}`);
Expand Down

0 comments on commit cc52a77

Please sign in to comment.