graphql - 未调用某些字段的 GraphQL 解析器
问题描述
我为学习目的编写了简单的 GraphQL 模式和解析器,但我无法理解为什么我的代码按预期工作的原因。我将 Prisma 用于 ORM,并用于编写express-graphql
API graphql-import
。
type User {
id: ID!
name: String!
}
type Link {
id: ID!
url: String!
user: User!
}
type Query {
links(id: ID!): [Link!]!
}
// resolvers
const links = async (root, args, ctx) => {
const links = await ctx.prisma.links({
where: {
user {
id: args.id
}
}
}
}
// resolver for `Link` type
const user = async (root, args, ctx) => {
const user = await ctx.prisma.link({ id: parent.id }).user()
return user
}
// omitted field resolver for `url` and `id`
module.exports = {
user
}
使用这些代码,我希望在查询时得到id
, url
,user
字段,但是当我发送查询时links
,它会返回字段。这意味着,如果我在服务器端签入,则根本不会调用字段解析器。这有什么问题?null
user
user
解决方案
推荐阅读
- c# - 选择列表中的最新项目,除非属性具有特定值
- wpf - WPF 应用程序未在 Windows Server 2016 的信号器集线器中连接
- html - 如何修复 div 使其不随溢出-y 移动?
- javascript - 为什么 window.requestAnimationFrame 只运行一次 step 函数?
- powerapps - Power App 门户与 Sharepoint 的集成
- mysql - 无法启动mysql服务器
- python - Keras 卷积自动编码器中的负损失
- selenium - Selenium chrome 驱动程序抛出密码字段不是棘手的错误
- c - main函数可以递归调用多少次?
- python - 整数超出范围。当我在 Python 中对字符串使用 to_numeric() 时