Objective
Learn how to generate random JSON data to test your Graphql scheme using JSON server and Mockaroo.
Prerequisites
- NodeJs installed
- expecting you to have intermediate knowledge of Javascript
- Terminal (any will do, preferably bash-based)
- A text editor (any will do)
Let’s get started
Create a project directory for the app.
mkdir simple_node_graphql_app && cd simple_node_graphql_app
install the local npm dependencies we require
npm install --save axios express express-graphql graphql nodemon
install global npm dependencies (read all about json-server)
npm install -g json-server
Generating test json data with Mockaroo
Step 1
Step 2
create a db.json
file
update the db.json
file with the data generated or download from mockaroo from step one.
Now let’s start our servers and see how far our applications are doing.
npm run dev
npm run js-server
Now we test the graphql query in our browser
Click here to clone and run the above app yourself.
I would love to hear your feedback and thoughts, also feel free to relate any issues you have.
How to thank me?
- give this article a clap
- follow me on twitter
- tweet, share this lesson with 3 friends
- star the project on github
Hope you’ll find this useful! Thanks
2 comments
This site was… how do I say it? Relevant!! Finally I’ve found something that helped me. Cheers!|
Like!! I blog frequently and I really thank you for your content. The article has truly peaked my interest.