A simple app to demonstrate GraphQL ๐
Make sure you have node version > 6
. If you have nvm
installed on your machine type nvm use
in the the root project directory.
-
git clone https://github.com/ghoshabhi/graphql-demo.git
-
cd graphql-demo/users
-
Install dependencies:
npm install
oryarn
-
To run the mock json-server run the following command:
npm run json:server
-
To run the GraphQL server:
npm run dev
- Get All Users:
query {
getAllUsers {
id
firstName
age
company {
name
description
}
}
}
- Fetch one User:
query {
getUser(id: "1") {
firstName,
age
}
}
- Fetch All Companies and its employees/users:
query {
getAllCompanies {
name
description
users{
firstName,
age
}
}
}
- Add User:
mutation {
addUser(firstName: "John Doe", age: 24) {
id
firstName
age
}
}
- Update User:
mutation updateInfo ($id: String!, $name: String, $age: Int){
updateUser(id: $id, firstName: $name, age: $age) {
id
firstName
age
}
}
And in Query Variables
add the following:
{
"id": "1",
"name": "Updated Name"
"age": 23
}