GraphQL – Node.js

This post have 3 examples


GitHub Repo with exampleBasic GraphQL Server in Node.js

The instructions are in the page then click GET STARTED choose the option JAVASCRIPT and follow the instructions.

— ( Optional ) you can do the practice “hello.js” exersice

Then click the link: “Express-GrapQL” and follow the instructions there. ( in my case I start a project using  “sudo npm init –y”  <– Not it the docs. )

Here is one basic code Example:


The next step on the evolution is the following example: 

where we are using an array of objects as hard coded database.

Here im using the following dependencies:

  • “express”: “^4.16.2”,
  • “express-graphql”: “^0.6.11”,
  • “graphql”: “^0.11.7”,
  • “lodash”: “^4.17.4”


Lodash is just to map through the object. (temporal)



Node.js + GraphQL + API

GitHub Repo: LINK

In the following example we are using GraphQL to administrate over an odinary API. This API is one that I create in a “db.json” file and will run a mini separate server for that app in the port 3000. this mini server with fake data is running using a NPM “json-server” you can create the db.json file in the same project folder just make sure to add “json:server” : “json-server –watch db.json” to the scripts. example:

Here is alink to the Database Hosted on GitHub: LINK

this server will be running on:   http://localhost:3000/users   to statr the server: sudo npm run json:server

To test you can plug the following API request on the browser address bar:

  • http://localhost:3000/characters
  • http://localhost:3000/characters/6
  • http://localhost:3000/games
  • http://localhost:3000/games/2
  • http://localhost:3000/games/1/characters


The Node-GraphQL server will be running on: http://localhost:4000/graphql

And here is the code:

Then you are ready to play with the queries:




Category: Database | Comments Off on GraphQL – Node.js



Website with info in how to install: LINK


Category: Database | Comments Off on Docker