11import  {  compose ,  last ,  prop ,  split  }  from  'ramda' 
22
3- import  {  getCategoryInfo ,  logDegradedSearchError  }  from  './utils' 
43import  {  formatTranslatableProp ,  shouldTranslateToBinding  }  from  '../../utils/i18n' 
54import  {  Slugify  }  from  '../../utils/slug' 
65import  {  APP_NAME  }  from  './constants' 
6+ import  {  getCategoryInfo ,  logDegradedSearchError  }  from  './utils' 
77
88const  lastSegment  =  compose < string ,  string [ ] ,  string > ( 
99  last , 
@@ -14,6 +14,28 @@ function cleanUrl(url: string) {
1414  return  url . replace ( / h t t p s : \/ \/ [ A - z 0 - 9 ] + \. v t e x c o m m e r c e s t a b l e \. c o m \. b r / ,  '' ) . toLowerCase ( ) 
1515} 
1616
17+ export  async  function  mountHrefRewritter ( {  url,  id } : any ,  _ : unknown ,  ctx : Context )  { 
18+     const  settings : AppSettings  =  await  ctx . clients . apps . getAppSettings ( APP_NAME ) 
19+ 
20+     if  ( shouldTranslateToBinding ( ctx ) )  { 
21+       try  { 
22+         const  rewriterUrl  =  await  ctx . clients . rewriter . getRoute ( id . toString ( ) ,  'anyCategoryEntity' ,  ctx . vtex . binding ! . id ! ) 
23+         if  ( rewriterUrl )  { 
24+           url  =  rewriterUrl 
25+         } 
26+       }  catch  ( e )  { 
27+         logDegradedSearchError ( ctx . vtex . logger ,  { 
28+           service : 'Rewriter getRoute' , 
29+           error : `Rewriter getRoute query returned an error for category ${ id }  , 
30+           errorStack : e , 
31+         } ) 
32+       } 
33+     } 
34+     const  pathname  =  cleanUrl ( url ) 
35+ 
36+     return  settings . slugifyLinks  ? Slugify ( pathname )  : pathname 
37+   } 
38+ 
1739/** This type has to be created because the Catlog API to get category by ID does not return the url or children for now. 
1840 * These fields only come if you get the category from the categroy tree api. 
1941 */ 
@@ -29,27 +51,7 @@ export const resolvers = {
2951
3052    cacheId : prop ( 'id' ) , 
3153
32-     href : async  ( {  url,  id } : SafeCategory ,  _ : unknown ,  ctx : Context )  =>  { 
33-       const  settings : AppSettings  =  await  ctx . clients . apps . getAppSettings ( APP_NAME ) 
34- 
35-       if  ( shouldTranslateToBinding ( ctx ) )  { 
36-         try  { 
37-           const  rewriterUrl  =  await  ctx . clients . rewriter . getRoute ( id . toString ( ) ,  'anyCategoryEntity' ,  ctx . vtex . binding ! . id ! ) 
38-           if  ( rewriterUrl )  { 
39-             url  =  rewriterUrl 
40-           } 
41-         }  catch  ( e )  { 
42-           logDegradedSearchError ( ctx . vtex . logger ,  { 
43-             service : 'Rewriter getRoute' , 
44-             error : `Rewriter getRoute query returned an error for category ${ id }  , 
45-             errorStack : e , 
46-           } ) 
47-         } 
48-       } 
49-       const  pathname  =  cleanUrl ( url ) 
50- 
51-       return  settings . slugifyLinks  ? Slugify ( pathname )  : pathname 
52-     } , 
54+     href : mountHrefRewritter , 
5355
5456    metaTagDescription : formatTranslatableProp < SafeCategory ,  'MetaTagDescription' ,  'id' > ( 
5557      'MetaTagDescription' , 
0 commit comments