2017-07-30 48 views
0

我有在响应此错误:不知道为什么我的cursorForObjectInConnection返回null?

不能用于非可空场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, 
     }; 
     }, 
    }, 

待办事项和newTodo从猫鼬数据库retreived。我想我正确地遵循这个相关的todo-modern sample。帮帮我?

回答

0

让我们尝试以下操作:

1)获取从DB待办事项像

const todos = await Todo.find({}); 

你可以得到待办事项特定用户,按您的Todo模式。 Todo.find({userid:context.user._id});

2)一旦你得到你的待办事项然后得到光标:

const cursor = offsetToCursor(todos.length); 

这为我工作。试一试。

相关问题