I am trying to save data in db using graphql but i am getting below error.
Error
{
"errors": [
{
"message": "Syntax Error: Expected Name, found String \"action\"",
"locations": [
{
"line": 4,
"column": 32
}
],
"extensions": {
"code": "GRAPHQL_PARSE_FAILED"
}
}
]
}
filterStr Data:
{"action":"count","demography":{"email_domain":"","age":{"from":"11-13-1919","to":"11-13-2018"},"gender":["male","female"],"company":"","phone":"","source":"","forms_submitted":"","added_by":"","education":"","occupation":"","interest":"","location":[],"paying_customer":""},"email":{"sent":[],"delivered":[],"opened":[],"clicked":[]}}
Codes:
const USER_TOKEN = sessionStorage.getItem("user_token");
const audienceName = JSON.stringify(this.state.audienceName);
const userId = sessionStorage.getItem("id");
const filterStr = JSON.stringify(filter);//without stringify it is insering as [Object, Object]
let dataQuery = {
query: `mutation{
createAudience(input:{data:{
audience_name:${audienceName},
filters:${filterStr},
created_by: ${userId},
}}){
audience{
id
}
}
}`
}
const add_new_audience = {
method: methodType,
url: constants.graphql,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${USER_TOKEN}`
},
data: JSON.stringify(dataQuery)
};
const resp = await axios(add_new_audience);
console.log(resp);
if(resp) {
this.props.history.push("/audiences");
}
Can anyone help me where i need to change the code?