Exercise: Read User Data from the Database
Understand how to connect a GraphQL backend to MongoDB by defining Mongoose schemas and implementing resolvers. This lesson guides you through reading user data, querying by author, and testing your GraphQL server with database integration.
It’s time to finish our integration with MongoDB. To do so, we must add a Mongoose schema for the users collection and update the remaining resolvers.
As before, this exercise provides a starter code, a walkthrough of the changes we need to implement, and, in case we get stuck, a solution code.
Exercise source code
To get the source code for this exercise, run the following command in the project’s repository:
git checkout db-resolver-exercise
Practice demo
{
"ext": "js,graphql",
"delay": 2000
}How to run the application
Our application has become a bit more complex, and we need to go through more steps to start it. Because it now reads data from a database, we need to start a database server.
npm run db:up
If the database isn’t seeded, we need ...