Skip to content

maxpou/graphql-nodejs-mongodb

Repository files navigation

GraphQL, NodeJS and MongoDB

Build Status Coverage Status Scrutinizer Code Quality

GraphQL server in Node.js using Express, MongoDB (and Mongoose).
Forked from: https://github.com/bruno12mota/graphql-nodejs. Many thanks to him :)

Installation&running

  1. Install dependencies

    npm install
  2. Populate MongoDB database

    mongoimport --db graphql --collection beers --jsonArray data.json
  3. Running: npm start

  4. Go to http://localhost:4000/graphql with your browser

## Requests sample

Queries

  • 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
      }
    }
    

Mutations

  • 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
    }
    

Tests

Run tests with: npm test and tests + code coverage with npm run coverage.

More informations about Chai.js Assertion Library.

About

POC with GraphQL, NodeJS and MongoDB

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •