首页 > 解决方案 > Not Found Status :404

问题描述

This is my first question here, although I always come to this great community for guidelines. I am learning how to use GraphQL watched a few videos on how to set it up and work with it as a project. I am cloning my GitHub repositories with Node.js for server interactions. My query works perfectly in the GraphQL playground, so I moved on to get the same data in my local editor; using Axios, I set up my server like below.


const { default: Axios } = require("axios");

// const fetch = require("node-fetch");




const username = "myGithubUsername"
const token = "myGithubPersonalAccessToken"

const body = {
    query:`
    query { 
        user(login: ${username}){
          name,
          login,
          bioHTML,
          avatarUrl,
          repositories(last: 10){
            nodes{
              name,
              id,
              forkCount
            }
          }
        }
      }`
}
const baseUrl = "https://api.github.com/graphql/";


const headers ={
    "Content-Type": "application/json",
    Authorization: `Bearer ${token}`
}
Axios.post(baseUrl,
    {body: JSON.stringify(body)},
    {headers: headers}).then((response) =>{
    console.log('response', response.data)
}).catch((error) => {
    console.log('error', error.response)})

Each time I serve it, I get Error: Status 404 Not Found.

I tried in PostMan using my Token, and it works perfectly too. Please let me know what I am doing wrong.

标签: node.jsgithubgraphql-js

解决方案


推荐阅读