【发布时间】:2021-03-15 12:17:10
【问题描述】:
我是 GraphQl 的新手,正在学习它。目前我有单个数据库表 - student_courses 如下所示:
student_id| student_name | course_code | course_name
1 ABC S-101 DataStructures
1 ABC S-150 NLP
1 ABC S-250 Machine learning
2 PQR S-101 DataStructures
3 XYZ S-101 DataStructures
3 XYZ S-150 NLP
我已将模型映射到单个 GraphQL 对象。因此,我将 GraphQL API 响应作为表中每一行的单独 json 对象。
我想了解如何按student_id, student_name 对该表的结果进行分组并获得以下格式的结果:
student_id, student_name, {course_code : course_name}
例如:1, "ABC", {"S-101":"DataStructures", "S-150":"NLP", "S-250":"Machine learning"}
我当前的 GraphQL 查询 -
{
student_courses() {
data {
student_id
student_name
course_code
course_name
}
}
}
【问题讨论】:
-
不查询责任 - 解析者角色
-
好的,如果你能指出 GraphQL 解析器上的一些好的参考实现来实现这一点,那就太好了。谢谢!
-
IDK ruby,在 ruby/rails 中关注一些关于 ORM 和 graphql 服务器的教程
标签: api graphql graphql-ruby