app.use(
'/graphql',
bodyParser.json(),
graphqlExpress(req => ({
schema,
context: {
models,
user: req.user,
},
})),
);
type Recipe {
id: Int!
authorName: String!
authorFbPage: String @virtual
perfumeName: String!
message: String
UserId: Int
}
type Query {
allRecipe: [Recipe]
meRecipe: [Recipe]
AvailableWatchRecipe: [Recipe]
}
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;
}
Write your answer...