我在回复时出现此错误:
对于不可为空的字段TodoEdge.cursor,不能返回null .
这是我的变异代码:
mutateAndGetPayload: async ({text}, context) => {
let newTodo = new TodoModel({ text, _creatorUserId: context.user._id });
await newTodo.save();
return {newTodo};
},
outputFields: {
todoEdge: {
type: GraphQLTodoEdge,
resolve: async ({newTodo}, args,context) => {
const todos = await getTodosByUserContext(context.user._id, 'any');
console.log("cursorForObjectInConnection = ",cursorForObjectInConnection(todos, newTodo)) // this logs null?
return {
cursor: cursorForObjectInConnection(todos, newTodo),
node: newTodo,
};
},
},
todos和newTodo是从mongoose数据库中检索出来的 . 我想我正在关注这个相关的todo-modern sample . 救命?
1 回答
让我们试试以下:
1)从您的数据库中获取待办事项
根据您的Todo架构,您可以为特定用户获取待办事项 . Todo.find({userid:context.user._id});
2)一旦你得到你的待办事项然后得到光标:
这对我有用 . 试试看 .