gpt4 book ai didi

javascript - GraphQL "Cannot return null for non-nullable"

转载 作者:IT老高 更新时间:2023-10-28 23:21:56 26 4
gpt4 key购买 nike

尝试制作我的第一个 graphQL 服务器,这是我目前所写的。

https://gist.github.com/tharakabimal/7f2947e805e69f67af2b633268db0406

当我尝试按用户名过滤用户时,GraphQL 上会弹出以下错误。

Error on GraphQL

错误发生在 UserQueriesQL.js 中的用户字段中。

我在解析函数上传递参数的方式有什么问题吗?

user: {
type: UserType,
args: {
username: {
name: 'username',
type: new GraphQLNonNull(GraphQLString)
}
},
resolve: function(parentValue, args) {
return User.find( args ).exec();
}

最佳答案

因为我是 GraphQL 的初学者,所以我也遇到了这个问题。单独浏览每个文件后,我发现我忘记导入到我的 resolvers

import User from './User';
**import Post from './Post';**

const resolvers = [User, **Posts**];

也许这会有所帮助!

关于javascript - GraphQL "Cannot return null for non-nullable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42409005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com