我在使用GraphQL时遇到了问题。我想发送axios.post请求到我的服务器。我可以在Postman中完成:
{
"query":"mutation{updateUserCity(userID: 2, city:\"test\"){id name age city knowledge{language frameworks}}} "
}
同时在GraphiQL中:
mutation {
updateUserCity(userID: 2, city: "test") {
id
name
age
city
knowledge {
language
frameworks
}
}
}
但是我无法在我的代码中做到这一点:(( 这是我的代码片段:
const data = await axios.post(API_URL, {
query: mutation updateUserCity(${ id }: Int!, ${ city }: String!) {
updateUserCity(userID: ${ id }, city: ${ city }){
id
name
age
city
knowledge{
language
frameworks
}
}
}
}, {
headers: {
'Content-Type': 'application/json'
}
})
我的代码有什么问题?