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

标签 javascript node.js express graphql

尝试制作我的第一个 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/

相关文章:

javascript - 如何将 "12000"显示为 "120.00"数值?

javascript - 如何重新加载具有链接 hasMany 关系的异步?

javascript - 带有图表的数据表查询

javascript - WebGLActiveInfo 函数是什么?

node.js - 在 Express 中生成 _csrf?

javascript - 单元测试 Controller 使用 Jest、NodeJS

mysql - JWT 管理员、用户等

javascript - NestJS + TypeORM - 连接到 mysql 和 mongodb 时出错

javascript - Node.js + Express.js 和 Hogan.js : returns a blank page sometimes

node.js - 尝试连接到本地 Express 服务器时出现 "Cannot GET/"