Skip to content

Good example for starter and learning GraphQL + NodeJS easily and fastly. (Just in 10 minutes)

License

Notifications You must be signed in to change notification settings

BaseMax/first-nodejs-graphql

Repository files navigation

First NodeJS GraphQL

Good example for starter and learning GraphQL + NodeJS easily and fastly. (Just in 10 minutes)

If you would like to read more, you can check out official documentation at here.

Using

$ yarn install
$ yarn start
  • Download MongoDB Compass and install from here.

Once MongoDB Compass is installed, you can open it to view your host and port details.

  • Make sure to update your database configuration in config/.env to match your MongoDB setup.

images of MongoCompass

  • Below are some images showcasing MongoDB Compass to help you get familiar with the interface.

first nodejs graphql

first nodejs graphql

first nodejs graphql

Then open: http://localhost:5000/graphql/?query=%7B%0A%20%20books%20%7B%0A%20%20%20%20id%2C%0A%20%20%20%20name%0A%20%20%7D%0A%0A%7D

Examples

List of all books id and name

{
  books {
    id,
    name
  }
}

first nodejs graphql

List of authors and their books

{
  authors {
    id
    name
    books {
      name
    }
  }
}

first nodejs graphql

List of authors name

{
  authors {
    name
  }
}

first nodejs graphql

List of books id

{
  books {
    id
  }
}

first nodejs graphql

Get a Single Book by args(Id)

{
  book(id:"66fdc7ab769dea390bb26fc8") {
    name
  }
}

first nodejs graphql

Add book by name and authorId

{
  mutation{
    addBook(name:"sincefiction",authorId:"66fdc6e7769dea390bb26fc4"){
    id,
    name
    }
  }
}

first nodejs graphql

Add author by name

{
  mutation{
    addAuthor(name:"max"){
    id,
    name
    }
  }
}

first nodejs graphql

Similar Repository

References


Max Base

My nickname is Max, Programming language developer, Full-stack programmer. I love computer scientists, researchers, and compilers. (Max Base)

Asrez Team

A team includes some programmer, developer, designer, researcher(s) especially Max Base.

Asrez Team