Skip to content

Instantly share code, notes, and snippets.

@katopz
Created August 30, 2016 04:33
Show Gist options
  • Save katopz/19490efc2cd6762956d769040c79d3b0 to your computer and use it in GitHub Desktop.
Save katopz/19490efc2cd6762956d769040c79d3b0 to your computer and use it in GitHub Desktop.
MongoDB+Mongoose+GraphQL or just MongoDB+GraphQL ref http://stackoverflow.com/questions/37237673/do-i-need-mongoose-with-graphql
resolve: () => {
return new Promise((resolve, reject) => {
db.collection('todos').find({}).toArray((err, todos) => {
if (err) reject(err)
else resolve(todos)
})
})
}
// ref https://www.compose.com/articles/using-graphql-with-mongodb/
var QueryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
todos: {
type: new GraphQLList(TodoType),
resolve: () => {
return new Promise((resolve, reject) => {
TODO.find((err, todos) => {
if (err) reject(err)
else resolve(todos)
})
})
}
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment