A small project using GraphQL with MongoDB in Express use for serve data for e-commerce website
This project makes use of ES6 which requires a 8+ version of Node https://nodejs.org/en/download/
In order to run this project you need to install MongoDB and ensure an instance is running. https://www.npmjs.com/package/mongodb
The following NPM modules are required in package.json:
- express
- express-graphql
- graphql
- mongoose
- babel-cli
- babel-preset-es2015
- nodemon
- jsonwebtoken
- graphql-iso-date
- cors
- bcrypt
- omise
- body-parser
Install with:
yarn install
npm dev is configured with nodmon so that the server automatically restarts when code files are changes
set DB=<your monogodb uri>
set SECRET=<secret_for_make_auth>
set OMISE_PUBLIC_KEY=<omise_public_key>
set OMISE_SECRET_KEY=<omise_secret_key>
yarn dev
yarn start
You can run these queries / mutations within GraphiQL, alternatively you can run them within a tool such as Postman. To do so ensure you POST the query / mutation in the body and set the content-type to GraphQL.
GraphQL doesn't care where your data is stored, in this case it's in a MongoDB.
userSchema.js uses a Mongoose Schemea and configures a number of exported functions for our GraphQL Resolvers to work with in order to load a user / list of users or create and update a user.
userType.js creates a GraphQLObjectType describing the structure of our data model.
userMutations.js and userQueries.js specify the operations available from GraphQL and link to our resolvers, in this case Mongoose operations that return a promise.