【问题标题】:Hashnode API with GraphQL API resulting in errorHashnode API 与 GraphQL API 导致错误
【发布时间】:2023-02-21 06:00:21
【问题描述】:

我正在尝试调用 hasnode API 以获取博客作为响应,正文在 GraphQL 中。但是我在“网络选项卡”中收到此错误“POST 正文丢失。你忘记使用 body-parser 中间件了吗? `

let query = `
    {
      user(username: "singhmona") {
        publication {
          posts{
            slug
            title
            brief
            coverImage
          }
        }
      }
    }
  `;

  let body = JSON.stringify({
            query
        });
   axios
      .post('https://api.hashnode.com/',
      body,
      {
        'content-type': 'application/json',
      })
      .then(response => {
        this.info = response;
        console.log(response);}
        )

`

【问题讨论】:

    标签: vue.js axios graphql


    【解决方案1】:

    我认为您应该尝试使用 fetch。在节点中使用 axios 时,我遇到了一个艰难的问题,我终于能够让 api 与 fetch 一起工作。这是对我有用的 sn-p。

    const getData = async() => {
    const query = `
            {
            user(username: "misiochaabel") {
                publication {
                    posts(page: 0) {
                        slug
                        title
                        brief
                        coverImage
                    }
                }
                }
            }
        `;
    
            const response = await fetch('https://api.hashnode.com/', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ query }),
            });
    
            const data = await response.json();
            console.log(data);
        }

    【讨论】:

      猜你喜欢
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多