GraphQL server in Node.js using Express, MongoDB (and Mongoose).
Forked from: https://github.com/bruno12mota/graphql-nodejs. Many thanks to him :)
-
Install dependencies
npm install
-
Populate MongoDB database
mongoimport --db graphql --collection beers --jsonArray data.json
-
Running:
npm start
-
Go to http://localhost:4000/graphql with your browser
## Requests sample
-
List all beers:
{ beers { name alcohol description } }
-
List all beers + filtering/sorting
{ beers(brewery: "Duvel", orderBy: ALCOHOL) { name alcohol } }
-
List all beers + brewery subresource
{ beers { name brewery { name location } } }
-
List one specific beer:
{ beer(id: "<yourIdHere>") { name } }
-
List all breweries:
{ breweries { name location } }
-
Adding a new beer:
mutation { addBeer(data: {name: "Delirium Tremens", brewery: "Huyghe Brewery", alcohol: 8.5}) }
-
Remove a specific beers
mutation { removeBeer(_id: "<yourIdHere>") { name } }
-
Remove all beers
mutation { removeAllBeers }
Run tests with: npm test
and tests + code coverage with npm run coverage
.
More informations about Chai.js Assertion Library.