Creating a GraphQL API with Express
To start the shopping cart system project, we first create a GraphQL API with Express. We start with the backend since we need it for both frontends. To get started, we have to add a few libraries that are needed to manipulate the SQLite database and add authentication to our app. Also, we need the library to enable Cross-Origin Resource Sharing (CORS) in our app.
CORS is a way to let us make requests from the browser to an endpoint hosted in a different domain from where the frontend is hosted.
To make our Express app accept GraphQL requests, we use the graphql
and express-graphql
libraries. To install both, we run the following command:
npm i cors jsonwebtoken sqlite3 express-graphql graphql
After installing the packages, we are ready to work on the code.
Working with resolver functions
First, we work on the resolver functions. To add them, we first add a resolvers
folder into the backend
folder. Then, we can work on the resolver...