File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 1- import  {  fetchUserPosts  }  from  "../utils/fetchPostData" ; 
1+ import  {  sort  }  from  "../utils/common" ; 
2+ import  {  fetchUserPosts  }  from  "../utils/fetchUserData" ; 
23
34export  default  { 
45 posts : async  ( parent ,  args ,  context )  =>  { 
56 try  { 
6-  return  await  fetchUserPosts ( parent . id ) ; 
7+  const  posts  =  await  fetchUserPosts ( parent . id ) ; 
8+  return  sort ( posts ,  "asc" ) ; 
79 }  catch  ( err )  { 
810 console . log ( err ) ; 
911 throw  new  Error ( err ) ; 
Original file line number Diff line number Diff line change @@ -21,3 +21,15 @@ export const fetchUser = async (userId) => {
2121 throw  new  Error ( err ) ; 
2222 } 
2323} ; 
24+ 
25+ //* fetch User's all Posts 
26+ //! returns [] if no data 
27+ export  const  fetchUserPosts  =  async  ( userId )  =>  { 
28+  try  { 
29+  const  posts  =  await  jsonPlaceholder . get ( `/users/${ userId }  /posts` ) ; 
30+  return  posts . data ; 
31+  }  catch  ( err )  { 
32+  console . log ( err ) ; 
33+  throw  new  Error ( err ) ; 
34+  } 
35+ } ; 
                                 You can’t perform that action at this time. 
               
                  
0 commit comments