Created
August 30, 2016 04:33
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resolve: () => { | |
return new Promise((resolve, reject) => { | |
db.collection('todos').find({}).toArray((err, todos) => { | |
if (err) reject(err) | |
else resolve(todos) | |
}) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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