GraphQL Cookbook
Logging in
5 min
logging in an existing user through the parse graphql api problem you want to log in an existing user in your backend through the parse graphql api solution using the parse graphql api, you can log in an existing user just by sending the user’s credentials through the login login mutation the username username and password password arguments are mandatory the mutation will return back all users’ fields, including the sessiontoken sessiontoken after logging in an existing user, you can use the authenticating an user https //www back4app com/docs/parse graphql/graphql user authentication recipe to send the sessiontoken sessiontoken in the following operations so they will be executed in the behavior of this user you can also use the logging out https //www back4app com/docs/parse graphql/graphql logout mutation recipe to destroy the sessiontoken sessiontoken version information depending on the version of parse you choose to run, the graphql queries, mutations and results will be slightly different please choose the correct example along with the parse version you are running parse server 3 10 0 and later request 1 mutation login{ 2 login(input { 3 username "somefolk" 4 password "somepassword" 5 }){ 6 viewer{ 7 user{ 8 id 9 createdat 10 updatedat 11 username 12 } 13 sessiontoken 14 } 15 } 16 } response 1 { 2 "data" { 3 "login" { 4 "viewer" { 5 "user" { 6 "id" "x1vzzxi6uhnoukj3y1yyrq==", 7 "createdat" "2020 02 06t13 38 04 517z", 8 "updatedat" "2020 02 06t13 38 04 517z", 9 "username" "somefolk" 10 }, 11 "sessiontoken" "r\ a5318d28821a78069f5b618de35b57bb" 12 } 13 } 14 } 15 } parse server 3 9 0 request 1 mutation login{ 2 login(fields { 3 username "somefolk" 4 password "somepassword" 5 }){ 6 id, 7 createdat, 8 updatedat, 9 username, 10 sessiontoken 11 } 12 } response 1 { 2 "data" { 3 "viewer" { 4 "sessiontoken" "r 1450d329038f876835fb7aac16742380", 5 "username" "somefolk" 6 } 7 } 8 } parse server 3 8 0 request 1 mutation login{ 2 login(fields { 3 username "somefolk" 4 password "somepassword" 5 }){ 6 objectid, 7 createdat, 8 updatedat, 9 username, 10 sessiontoken 11 } 12 } response 1 { 2 "data" { 3 "login" { 4 "objectid" "ktznkvzto2", 5 "createdat" "2019 11 04t14 23 46 014z", 6 "updatedat" "2019 11 04t14 23 46 014z", 7 "username" "somefolk", 8 "sessiontoken" "r\ fe39d9de406d53d13e9af1efbbe967a8" 9 } 10 } 11 } parse server 3 7 2 request 1 mutation login { 2 users { 3 login(username "somefolk", password "somepassword") { 4 objectid, 5 createdat, 6 updatedat, 7 username, 8 sessiontoken 9 } 10 } 11 } response 1 { 2 "data" { 3 "users" { 4 "login" { 5 "objectid" "nyu1lnlhpd", 6 "createdat" "2019 07 29t09 09 58 222z", 7 "updatedat" "2019 07 29t09 09 58 222z", 8 "username" "somefolk", 9 "sessiontoken" "r\ cbca71d29d7601761b48ed01bbe9638d" 10 } 11 } 12 } 13 }