Graphql don';我不知道为什么cursorForObjectInConnection返回null?
我在回答时出现以下错误: 对于不可为null的字段TodoEdge.cursor,无法返回null 这是我的变异代码:Graphql don';我不知道为什么cursorForObjectInConnection返回null?,graphql,relayjs,graphql-js,relaymodern,Graphql,Relayjs,Graphql Js,Relaymodern,我在回答时出现以下错误: 对于不可为null的字段TodoEdge.cursor,无法返回null 这是我的变异代码: mutateAndGetPayload: async ({text}, context) => { let newTodo = new TodoModel({ text, _creatorUserId: context.user._id }); await newTodo.save(); return {newTodo};
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数据库检索到的。我认为我正确地遵循了这一点。帮忙 让我们尝试以下内容:
1) 从数据库中获取任务
const todos = await Todo.find({});
您可以根据Todo模式获取特定用户的Todo。find({userid:context.user.\u id})
2) 一旦你得到你的待办事项,然后得到光标:
const cursor = offsetToCursor(todos.length);
这对我有用。试试看。让我们试试以下几点:
1) 从数据库中获取任务
const todos = await Todo.find({});
您可以根据Todo模式获取特定用户的Todo。find({userid:context.user.\u id})
2) 一旦你得到你的待办事项,然后得到光标:
const cursor = offsetToCursor(todos.length);
这对我有用。试试看