mutation {
registerUser(username: "johndoe", email: "[email protected]", password: "wizzyekpot" ){
token
}
}
We should get something like this:
{
"data": {
"registerUser": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJzaW1peXV3aXJlQGdtYWlsLmNvbSIsImlhdCI6MTYwNjM3NjkzMSwiZXhwIjoxNjA2NDYzMzMxfQ.mJyxkUlDevOaS2Wy-GKlZrQPOVjOnippPwtXTDTfToI"
}
}
}
Let’s now log in with the user details we just created:
mutation {
login(email:"[email protected]" password:"123456"){
token
}
}
We should get something like this:
{
"data": {
"login": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJzaW1peXV3aXJlQGdtYWlsLmNvbSIsImlhdCI6MTYwNjM3NjkzMSwiZXhwIjoxNjA2NDYzMzMxfQ.mJyxkUlDevOaS2Wy-GKlZrQPOVjOnippPwtXTDTfToI"
}
}
}
For us to query a single user, we need to pass the user token as authorization header. Go to the HTTP Headers tab. …and paste this:
{
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJzaW1peXV3aXJlQGdtYWlsLmNvbSIsImlhdCI6MTYwNjM3NjkzMSwiZXhwIjoxNjA2NDYzMzMxfQ.mJyxkUlDevOaS2Wy-GKlZrQPOVjOnippPwtXTDTfToI"
}
Here’s the query:
query myself{
me {
id
email
username
}
}
And we should get something like this:
{
"data": {
"me": {
"id": 1,
"email": "[email protected]",
"username": "johndoe"
}
}
}
query singleUser{
user(id:1){
id
email
username
}
}
{
allUsers{
id
username
email
}
}