Parissai / learn-graphql

Learn GraphQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A simple project to learn GraphQL

Why use GraphQL:

  • Type inspection
  • Query multiple DBs from one GraphQL server
  • Flexibility of the queries

How to run locally

  • Clone the project: git clone git@github.com:Parissai/learn-graphql.git
  • Install dependencies: npm i
  • Install MongoDB
  • Create a directory for the data: mkdir -p /data/db OR if you don't have admin access: sudo mkdir -p /data/db
  • Make sure that you have access to the directory you just created: sudo chmod 777 /data/db
  • Get MongoDB started with mongod in one terminal
  • Run the server in another terminal: npm start

Test create mutation

mutation {
  createContact(input: {
    firstName: "Par",
    lastName: "issa",
    company: "FAC"
  }) {
    id
  }
}

Test getContacts query

query {
  getContacts {
    id
    firstName
    lastName
    company
  }
}

Test update mutation

mutation {
  updateContact({input: {
    id: "5c2bde3403cad61267d308ad"
    firstName: "Parissa"
    lastName: "S"
    company: "Founders&Coders"
  }}), {
  firstName
  lastName
  company
  }
}

Test delete mutation

mutation {
  deleteContact(id: "5c2c0fb12e03c8543f4fe538")
}

About

Learn GraphQL


Languages

Language:JavaScript 100.0%