GraphQl API with Node ๐
git clone https://github.com/manaraph/getting-started-with-graphql.git
- cd getting-started-with-graphql.
- To play around with graphql run npm install and then npm run trial
- Navigate into config folder and rename env.global to .env
- Setup your environment variables:
- Set your host url default is http://localhost or http://127.0.0.1
- Set up your port default is 4000
- Add your MongoDB URI eg. "mongodb://:@xxxxxxxx.mlab.com:57097/dbname"
- Sign up on mlab.
- Create a database, you use the free version for aws, google cloud or azure.
- Create a user and password for your database (this correspond to your and as seen in your MongoDB URI).
- Please note the URI set in the url './config/.env.global' won't work. (this just a guide on how the URI looks like).
# install dependencies
npm install
# Play with grapql app in at localhost:4000
npm run trial
# serve app in developer mode at localhost:4000
npm run dev
# serve app on production mode at localhost:4000
npm start
mutation {
addUser(id: "1", name: "Omachonu Manasseh", email: "[email protected]") {
id
name
email
}
}
mutation {
deleteUser(id: "1", name: "Omachonu Manasseh", email: "[email protected]") {
id
name
email
}
}
query {
users {
id
name
email
}
}
query {
user(id: "1") {
id
name
email
}
}
Adapted from:
- Creating a GraphQL server with NodeJS - Aman Mittal
- How to set up a GraphQL Server using Node.js, Express & MongoDB - Leonardo Maldonado