【问题标题】:How to post Object data using Axios and GraphQL如何使用 Axios 和 GraphQL 发布对象数据
【发布时间】:2019-06-18 20:48:57
【问题描述】:

我正在尝试使用变异查询和 axios 发布名称为 city 的对象数据,但出现错误状态代码:400 Bad Request。

  axios.post('http://localhost:5000/graphql/', {
  query: `
  mutation ($city:cityInput!) {
    createCity (city:$city) {
      id
      cityName
    }
  }
`,
  variables:
    '{ "city": {"cityName": "test", "cityCode": "0001", "cityEnName": "test", "cityTwName": "test", "postCode": "0001", "provinceID": 1 }}',
})
.then(res => console.log(res))
.catch(err => console.log(err));

也许是因为我使用了对象数据?但我更喜欢使用对象数据。请帮助我,提前谢谢。

【问题讨论】:

    标签: graphql axios


    【解决方案1】:

    我测试了你的代码确实可以工作

    客户:

    axios.post('https://o5okynl7jy.sse.codesandbox.io/', {
      query: `
      mutation ($city: CityInput!) {
        createCity (city: $city) {
          id
          cityName
        }
      }`,
      variables:
        '{ "city": {"cityName": "test", "cityCode": "0001", "cityEnName": "test", "cityTwName": "test", "postCode": "0001", "provinceID": 1 }}',
    })
    .then(res => console.log(res))
    .catch(err => console.log(err));
    

    服务器:

    https://codesandbox.io/s/o5okynl7jy

    【讨论】:

      猜你喜欢
      • 2021-11-15
      • 1970-01-01
      • 2023-03-26
      • 2018-06-20
      • 2019-01-08
      • 2017-09-14
      • 2021-11-23
      • 2018-12-25
      • 2021-02-16
      相关资源
      最近更新 更多