CRUD operation of differnt Authenication, User, Profile and Cities with GraphQL.
npm install
npm run dev
http://[DOMAIN]:[PORT]/graphql
Basic User Authentication
MUTATION register
mutation Mutation(
$name: String!
$email: String!
$password: String!
$role: AllowedRoles!
) {
register(name: $name, email: $email, password: $password, role: $role) {
message
}
}
Variables
name: "yatin",
email: "[email protected]",
password: "test",
role: "admin" || "users"
MUTATION verify
mutation Mutation($verifyId: String!) {
verify(id: $verifyId) {
message
}
}
Variables
verifyId: "61856a59c261f2738388d088"
MUTATION forgetPassword
mutation ForgetPassword($email: String!) {
forgetPassword(email: $email) {
resetToken
message
}
}
Variables
email: "[email protected]"
MUTATION reset
mutation Reset($resetToken: String!, $password: String!) {
reset(resetToken: $resetToken, password: $password) {
message
}
}
Variables
resetToken: "2MzcxMDExfQ.43X3Rxfx-aoUCMdYxrgMGcFUs5inGBK6H1GDiF3PlY4"
password: "test"
MUTATION login
mutation MUTATION($email: String!, $password: String!) {
login(password: $password, email: $email) {
message
token
user {
_id
verified
urlGitHub
urlTwitter
name
email
role
phone
city
country
createdAt
updatedAt
}
}
}
Variables
email: "[email protected]",
password: "test"
QUERY token
query Token {
token {
token
}
}
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIs.eyJfaWQiOiI2MTg1NmE1OW
Basic User CRUD operation
QUERY Users
query Users($page: Int, $limit: Int, $sort: String, $order: Int) {
users(page: $page, limit: $limit, sort: $sort, order: $order) {
_id
name
email
role
verified
phone
city
country
urlTwitter
urlGitHub
createdAt
updatedAt
}
}
Variables
"page": 1,
"limit": 5,
"sort": "name",
"order": 1
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIs.eyJfaWQiOiI2MTg1NmE1OW
MUTATION register
mutation CreateUser($input: createUserInput) {
createUser(input: $input) {
message
user {
_id
name
email
role
verified
phone
city
country
urlTwitter
urlGitHub
updatedAt
createdAt
}
}
}
Variables
input {
name: "yatin",
email: "[email protected]",
password: "test",
role: "admin" || "users"
city: "delhi",
country: "india",
phone: "13124242323"
}
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIs.eyJfaWQiOiI2MTg1NmE1OW
MUTATION DeleteUser
mutation DeleteUser($id: String!) {
deleteUser(id: $id) {
message
}
}
Variables
id: "618804402d5ee64df0d277d9"
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIs.eyJfaWQiOiI2MTg1NmE1OW
QUERY SingleUser
query SingleUser($id: String!) {
singleUser(id: $id) {
user {
_id
name
email
role
verified
phone
city
country
urlTwitter
urlGitHub
createdAt
updatedAt
}
}
}
Variables
id: "61856a59c261f2738388d088"
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIs.eyJfaWQiOiI2MTg1NmE1OW
MUTATION updateUser
mutation Mutation($id: String!, $userDetails: UserDetailsInput!) {
updateUser(id: $id, userDetails: $userDetails) {
message
}
}
Variables
id: "6182bc91a1be9b300dda0ce1",
userDetails: {
email: "[email protected]",
name: "test",
role: "user",
phone: "3242423",
city: "delhi",
country: "UK"
}
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIs.eyJfaWQiOiI2MTg1NmE1OW
Basic Profile CRUD operation
QUERY Profile
query Profile {
profile {
name
_id
email
role
verified
phone
city
country
urlTwitter
urlGitHub
createdAt
updatedAt
}
}
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIs.eyJfaWQiOiI2MTg1NmE1OW
MUTATION updateProfile
mutation UpdateProfile($userDetails: UserDetailsInput!) {
updateProfile(userDetails: $userDetails) {
message
}
}
Variables
userDetails: {
email: "[email protected]",
name: "test",
role: "user",
phone: "3242423",
city: "delhi",
country: "India"
}
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIs.eyJfaWQiOiI2MTg1NmE1OW
MUTATION changePassword
mutation ChangePassword($oldPassword: String!, $newPassword: String!) {
changePassword(oldPassword: $oldPassword, newPassword: $newPassword) {
message
}
}
Variables
oldPassword: "test2",
newPassword: "test"
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIs.eyJfaWQiOiI2MTg1NmE1OW
Basic Cities CRUD operation
QUERY allCity
query Query {
allCity {
name
_id
}
}
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIs.eyJfaWQiOiI2MTg1NmE1OW
GET /cities?filter=Bucaramanga&fields=name&page=1&limit=5&sort=name&order=1
curl --location -g --request GET 'http://[DOMAIN]:[PORT]/cities?filter=Bucaramanga&fields=name&page=1&limit=5&sort=name&order=1'
--header 'Authorization: Bearer [AUTH_TOKEN_STRING]'
POST /cities
curl --location -g --request POST 'http://[DOMAIN]:[PORT]/cities'
--header 'Authorization: Bearer [AUTH_TOKEN_STRING]'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'name=Miami'
GET /cities/5bd08db979bbc504c14ebfdd
curl --location -g --request GET 'http://[DOMAIN]:[PORT]/cities/5bd08db979bbc504c14ebfdd'
--header 'Authorization: Bearer [AUTH_TOKEN_STRING]'
--header 'Accept-Language: es'
PATCH /cities/5bd08db979bbc504c14ebfdd
curl --location -g --request PATCH 'http://[DOMAIN]:[PORT]/cities/5bd08db979bbc504c14ebfdd'
--header 'Authorization: Bearer [AUTH_TOKEN_STRING]'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'name=Seatle2'
DELETE /cities/5b38171b1843d58427c5d6c4
curl --location -g --request DELETE 'http://[DOMAIN]:[PORT]/cities/5b38171b1843d58427c5d6c4'
--header 'Authorization: Bearer [AUTH_TOKEN_STRING]'
--data-urlencode 'name=Seatle2'