[英]Calling graphQL server mutation to axios url
我目前在客户端使用GraphQL Server和axios。 我想知道如何在我的axios上调用这个graphQL
mutation {
createUser(email: "hello@gmail.com") {
email
}
}
我怎么这样称呼它?
const res = await axios.get('http://localhost:5000/public?query={users{email}');
您需要使用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)
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.