【问题标题】:Calling graphQL server mutation to axios url调用graphQL服务器突变到axios url
【发布时间】:2019-06-22 02:08:20
【问题描述】:

我目前在客户端使用 GraphQL Server 和 axios。 我想知道如何将此 graphQL 调用到我的 axios

mutation {
 createUser(email: "hello@gmail.com") {
   email
 }
}

我怎么能这样称呼它?

const res = await axios.get('http://localhost:5000/public?query={users{email}');

【问题讨论】:

标签: javascript reactjs graphql axios


【解决方案1】:

您需要使用post 方法将您的查询/突变发送到 GraphQL 服务器:

axios({
  // Of course the url should be where your actual GraphQL server is.
  url: 'http://localhost:5000/graphql',
  method: 'post',
  data: {
      query: `
        mutation createUser($email: email){
            createUser(email: $email) {
               email
            }
        }`,
     variables: {
        email: "hello@gmail.com"
     }
  }
}).then((result) => {
    console.log(result.data)
});

【讨论】:

  • @Overwatch "It's not working" 在调试方面并没有真正的帮助。你能提供更多信息吗?您收到任何错误消息吗?
  • 这只是一个错误,是的,它工作正常我只是在查询部分有点困惑,但它现在可以工作了。谢谢。
猜你喜欢
  • 2020-09-11
  • 2019-01-08
  • 2019-06-30
  • 2020-02-14
  • 1970-01-01
  • 1970-01-01
  • 2018-02-05
  • 2019-08-03
  • 2017-01-21
相关资源
最近更新 更多