update request util
This commit is contained in:
		
							parent
							
								
									001062db21
								
							
						
					
					
						commit
						208076e7f4
					
				
					 3 changed files with 55 additions and 52 deletions
				
			
		| 
						 | 
				
			
			@ -5,7 +5,8 @@ async function fetchRepo(username, reponame) {
 | 
			
		|||
    throw new Error("Invalid username or reponame");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const res = await request(`
 | 
			
		||||
  const res = await request({
 | 
			
		||||
    query: `
 | 
			
		||||
      fragment RepoInfo on Repository {
 | 
			
		||||
        name
 | 
			
		||||
        stargazers {
 | 
			
		||||
| 
						 | 
				
			
			@ -31,9 +32,11 @@ async function fetchRepo(username, reponame) {
 | 
			
		|||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
  `, {
 | 
			
		||||
    `,
 | 
			
		||||
    variables: {
 | 
			
		||||
      login: username,
 | 
			
		||||
      repo: reponame,
 | 
			
		||||
    },
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  const data = res.data.data;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,8 @@ require("dotenv").config();
 | 
			
		|||
async function fetchStats(username) {
 | 
			
		||||
  if (!username) throw Error("Invalid username");
 | 
			
		||||
 | 
			
		||||
  const res = await request(`
 | 
			
		||||
  const res = await request({
 | 
			
		||||
    query: `
 | 
			
		||||
      query userInfo($login: String!) {
 | 
			
		||||
        user(login: $login) {
 | 
			
		||||
          name
 | 
			
		||||
| 
						 | 
				
			
			@ -29,7 +30,9 @@ async function fetchStats(username) {
 | 
			
		|||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
  `, { login: username });
 | 
			
		||||
    `,
 | 
			
		||||
    variables: { login: username }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  const stats = {
 | 
			
		||||
    name: "",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ function kFormatter(num) {
 | 
			
		|||
    : Math.sign(num) * Math.abs(num);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function request(query, variables) {
 | 
			
		||||
function request(data) {
 | 
			
		||||
  return new Promise((resolve, reject) => {
 | 
			
		||||
    axios({
 | 
			
		||||
      url: "https://api.github.com/graphql",
 | 
			
		||||
| 
						 | 
				
			
			@ -35,10 +35,7 @@ function request(query, variables) {
 | 
			
		|||
      headers: {
 | 
			
		||||
        Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
 | 
			
		||||
      },
 | 
			
		||||
      data: {
 | 
			
		||||
        query,
 | 
			
		||||
        variables,
 | 
			
		||||
      },
 | 
			
		||||
      data,
 | 
			
		||||
    })
 | 
			
		||||
      .then((response) => resolve(response))
 | 
			
		||||
      .catch((error) => reject(error));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue