GraphQL Expected Iterable, but did not find one for field xxx.yyy

Answer • 1 Asked • Jun 24 2019
Currently I am using Apollo/GraphQL/Node.js/Sequelize to build my backend server, and my server code looked like below, in there I can use req.user to get the current login user
app.use( '/graphql', bodyParser.json(), graphqlExpress(req => ({ schema, context: { models, user: req.user, }, })), );

Now I have two models User and Recipe, and the association rule is Recipe belongs to User, so in the Recipe schema I can use the UserId to know which user create this schema, the Recipe schema is
type Recipe { id: Int! authorName: String! authorFbPage: String @virtual perfumeName: String! message: String UserId: Int } type Query { allRecipe: [Recipe] meRecipe: [Recipe] AvailableWatchRecipe: [Recipe] }

My problem is in the meRecipe part, this Query supposed to be able to show the recipes created by login user, the resolver code is:
meRecipe: async (parent, args, { models, user }) => {
if (user) { console.log(user.id); console.log(user.username); return models.Recipe.find({ where: { UserId: user.id } }) .then((result) => { return result }); } return null; }

You can see I also use the console.log to check whether I can get the current user information, it actually can, so I am really confused why when I run this Query in the GraphQL server, it always shows"message": "Expected Iterable, but did not find one for field Query.meRecipe

Write your answer...

On a mission to build Next-Gen Community Platform for Developers