graphql - Graphql 属于关系
问题描述
所以我正在学习 GraphQL,并且我试图在构建模式时了解我是如何处理关系的。所以我有一个带有字段 show 的 Apps 表,其中设置了 Show 表的外键。如何在 graphql 模式中执行此操作?这就是我目前所拥有的
const schema = buildSchema(`
type Query {
app: App
}
type App {
id: Int
show: Int
name: String
url: String
author: String
price: Float
image: String
}
type Show {
id: Int
name: String
airDate: String
}
`);
也许我需要一些东西来告诉它这段关系?谢谢
解决方案
您通常会设置 GraphQL 架构来引用另一个对象,并且在引用者中根本没有它的 ID:
type App {
id: Int
show: Show
...
}
type Show {
id: Int
name: String
...
}
这样,查询就不必知道涉及到中间数据库查找
query GetApp {
app {
name
url
show { name }
}
}
推荐阅读
- flutter - 如何在我的 Flutter 应用程序中显示可关闭的教程叠加层?
- kubernetes - 如何在 GKE 中创建具有 ReadWriteMany 访问权限的动态持久卷声明?
- neo4j - Cypher 可变路径条件过滤
- docker - Docker Build 文件权限错误并返回非零代码:126
- html - 根据 mime 类型,在弹出窗口中打开 PDF 或下载 word 文档
- java - Ctrl-Shift-I 检查快捷方式不起作用。充当制表键
- javascript - 服务:找不到命令React js部署
- java - ViewBinding 与 Java11,AndroidStudio 总是显示错误(但运行没有任何问题)
- java - JSON子类缺少类字段输出
- elasticsearch - 在 Kibana 索引中获得最高索引率 (/s) 和搜索率的更可靠方法。每个过去的时间段