I am trying to use GraphQL with mysql in a node js express server.
but I am getting this error everytime I run my query
here is the error:
{
"errors": [
{
"message": "Expected Iterable, but did not find one for field \"RootQueryType.getAllGoals\".",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"getAllGoals"
]
}
],
"data": {
"getAllGoals": null
}
}
here is my Graphql Query:
query {
getAllGoals {
title
progress
goal
}
}
I get the result expected from "SELECT * FROM (my table)", but it gives me an error when I try to return it for GraphQL from the resolver as shown in the code below:
const RootQuery = new GraphQLObjectType({
name: "RootQueryType",
fields: {
getAllGoals: {
type: new GraphQLList(GoalType),
resolve(parent, args) {
return db.query("SELECT * FROM myTable", (err, result) => {
if (err) throw err
console.log(JSON.parse(JSON.stringify(result)))
return JSON.parse(JSON.stringify(result))
})
}
}
}
})
I have checked to see if I have any conflicts in my GraphQLObjectType GoalType, but I had none.