graphql - prisma graphql pass argument to a nested query
问题描述
I have a graphql query that pulls a Business by id , and then retrive all the reviews related to that business.
query Business($id: ID!) {
business(id: $id) {
_id
name
desc
reviews {
_id
text
createdAt
published
}
}
the challenge I had is I would like to pull only the published reviews. I was able to acheive this by using a field resolver. however I am not too sure if it is the best way because the query already did the heavy work of pulling all the reviews and the reolver only filter the published ones.
const Business = {
reviews: (parent, args, ctx, info) => parent.reviews.filter(rev => rev.published)
}
below is my resolver with prisma query :
async business(parent, args, { prisma, request }, info) {
let opArgs = {}
opArgs.where = { _id: args.id }
let post = null
try {
post = await prisma.query.business(opArgs, info)
console.log(post)
} catch (err) {
throw new Error(err.message)
}
return post
},
my goal is to filter on the published review on the root. is there a better way to approach this.
any help please
解决方案
你不能通过 id 和发布键查询评论吗?选择所有评论并过滤它们是没有意义的。
推荐阅读
- angular - 来自登录页面的 Angular 隐藏导航栏菜单
- javascript - android输入键事件在jquery中不起作用
- amazon-web-services - 如何将 s3 数据从一个 EMR 集群读取到另一个 EMR 集群?
- r - 我在 R 中收到 nlme 包的功能错误
- python - 在 Python 中的进程之间共享列表的正确方法?
- react-native - React 本机应用程序需要时间来加载资产?
- python - python版本检查命令仅在用户模式下有效,不适用于root
- charles-proxy - 无法从使用 Charles 在 Android 上运行的特定应用程序获取 API 调用日志
- ajax - 集成 Paypal 时出现跨域请求被阻止错误
- php - 如何将特定结构数组转换为“树”结构数组?