Calling a query inside a mutation #2929
Answered
by
zackshen
spidertwin2
asked this question in
Q&A
-
Hello, getBlogs - query MongoDB by userId, return all documents linked to userId. I don't know how to call getBlogs inside updateUsersBlogs. getBlogs.ts
getUsersBlogs.ts
Thanks 🌳 |
Beta Was this translation helpful? Give feedback.
Answered by
zackshen
Nov 8, 2021
Replies: 1 comment 1 reply
-
hi @spidertwin2 , the code like below, import getBlogs from './getBlogs'
export default resolver.pipe(resolver.authorize(), async (userIds: string[], ctx) => {
try {
const userBlogs = await Promise.all(userIds.map((userId) => getBlogs(userId).then(blogs => ({ userId, blogs}))))
return userBlogs
} catch (error) {
console.log("Error updating users: ", error)
}
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
spidertwin2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi @spidertwin2 , the code like below,