An example of a simple GraphQL server with NodeJS, express-graphql and knex with PostgreSQL, which is serving GraphQL API for e-commerce website featuring:
- Get product details
- Get cart details
- Add / update / remove items from cart
- Install Node.js version 16 or above
- Running PostgreSQL on port 5432
- Set up
.env
file with database information, please refer to the format of.env.default
- Run
yarn install
- Make sure you have PostgreSQL running on port 5432. You can download PostgreSQL from here
- Set up
.env
file with database host, port, name, user and password. Please refer to.env.default
for exact format. - Run
yarn setDatabase
to set up schema on database - Run
yarn seedDatabase
to fill in sample data to database - Run
yarn build
- Run
yarn start
to start the application
Navigate to http://localhost:5000/graphql to see the GraphQL introspection.
cartById(id: Int): Cart
productById(id: Int): Product
productByName(name: String): Product
addProductToCart(productId: Int, cartId: Int): Cart
removeProductFromCart(productId: Int, cartId: Int): Cart
UpdateProductQuantityToCart(productId: Int, cartId: Int, quantity: Int): Cart
Generated by GraphQL Voyager