File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -67,5 +67,24 @@ describe("LeetCode", () => {
6767            } ) ; 
6868            expect ( data . user . username ) . toBe ( "LeetCode" ) ; 
6969        } ) ; 
70+ 
71+         it ( "should be able to use graphql noj-go" ,  async  ( )  =>  { 
72+             const  {  data }  =  await  lc . graphql ( 
73+                 { 
74+                     operationName : "data" , 
75+                     variables : {  username : "LeetCode"  } , 
76+                     query : ` 
77+                 query data($username: String!, $year: Int) { 
78+                     calendar: userCalendar(userSlug: $username, year: $year) { 
79+                       streak 
80+                       totalActiveDays 
81+                       submissionCalendar 
82+                     } 
83+                   }` , 
84+                 } , 
85+                 "/graphql/noj-go/" , 
86+             ) ; 
87+             expect ( typeof  data . calendar . streak ) . toBe ( "number" ) ; 
88+         } ) ; 
7089    } ) ; 
7190} ) ; 
Original file line number Diff line number Diff line change @@ -93,15 +93,19 @@ export class LeetCodeCN extends EventEmitter {
9393    /** 
9494     * Use GraphQL to query LeetCodeCN API. 
9595     * @param  query 
96+      * @param  endpoint Maybe you want to use `/graphql/noj-go/` instead of `/graphql/`. 
9697     * @returns  
9798     */ 
98-     public  async  graphql ( query : LeetCodeGraphQLQuery ) : Promise < LeetCodeGraphQLResponse >  { 
99+     public  async  graphql ( 
100+         query : LeetCodeGraphQLQuery , 
101+         endpoint  =  "/graphql/" , 
102+     ) : Promise < LeetCodeGraphQLResponse >  { 
99103        await  this . initialized ; 
100104
101105        try  { 
102106            await  this . limiter . lock ( ) ; 
103107            const  BASE  =  BASE_URL_CN ; 
104-             const  res  =  await  fetch ( `${ BASE } /graphql ` ,  { 
108+             const  res  =  await  fetch ( `${ BASE } ${ endpoint }  ` ,  { 
105109                method : "POST" , 
106110                headers : { 
107111                    "content-type" : "application/json" , 
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export interface ICredential {
4444// LeetCode GraphQL 
4545export  interface  LeetCodeGraphQLQuery  { 
4646    operationName : string ; 
47-     variables : {  [ key : string ] : unknown  } ; 
47+     variables ? : {  [ key : string ] : unknown  } ; 
4848    query : string ; 
4949} 
5050
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments