Skip to content

Instantly share code, notes, and snippets.

@HERRKIN
Last active January 13, 2017 15:16
Show Gist options
  • Save HERRKIN/101e0a2f3aaa545838f3d53054de5724 to your computer and use it in GitHub Desktop.
Save HERRKIN/101e0a2f3aaa545838f3d53054de5724 to your computer and use it in GitHub Desktop.
addTodo resolver
import {Todos} from '../../../../lib/Collections'
export default function (root, options, context) {
// it wont let anonymous users create a todo
if (!context.userId) {
throw new Error('Unknown User (not logged in)')
}
// pack the todo adding the userId as the owner id
const newTodo = {
text: options.text,
completed: false,
owner: context.userId
}
const TodoId = Todos.insert(newTodo)
if (TodoId) {
const todo = {_id: TodoId, ...newTodo}
// log the todo so we know the todo was inserted correctly via the console
console.log(todo)
return todo // return the todo
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment