I've been having trouble sending GraphQL queries to my GraphQLJS backend, I copy and pasted the query that I use in GraphiQL (that works fine) but it's causing a syntax error: {"errors":[{"message":"Syntax Error: Expected :, found String \": \"","locations":[{"line":2,"column":45}]}]}
graphQLTest = async () => {
var data = {
query: `mutation {
createAuctionOffering(features:"{\"year\": \"2002\", \"model\":{\"make\":\"honda\", \"selectedModel\":\"civic\"}}", start_time:"2019-03-15 19:05:45.109+00", duration:"2019-03-15 19:05:45.109+00"){
auc_id
}
}`,
}
// data = await JSON.stringify(data)
var token = jwt.sign({name:data}, 'LIdXNnmK2qJNyTGs456bR0iebf9eGZV7', {expiresIn: '10s'});
let response = await fetch('http://localhost:8000/graphql', {
method: 'post',
headers: {
"User": "charlesdsmith25@gmail.com",
"Content-Type": "application/json"
},
body: JSON.stringify({name:token})
})
let jsonResponse = await response.text()
console.log(jsonResponse)
}
I've also been using JWT but that isn't an issue seeing as the query makes it through to the backend and raises the syntax error. This is the query I'm trying to send:
var data = {
query: `mutation {
createAuctionOffering(features:"{\"year\": \"2002\", \"model\":{\"make\":\"honda\", \"selectedModel\":\"civic\"}}", start_time:"2019-03-15 19:05:45.109+00", duration:"2019-03-15 19:05:45.109+00"){
auc_id
}
}`,
}
It seems like the problems lies with the quotes