Signing up a user through the Parse GraphQL API
Problem
You want to sign up a new user in your backend through the Parse GraphQL API.
Solution
Using the Parse GraphQL API, you can sign up a new user just by sending the user’s data through the signUp
mutation. The username
and password
fields are mandatory. The mutation will return back not only the objectId
and createdAt
fields (that are returned by default when creating an object), but also the sessionToken
.
After signing up a new user, you can use the authenticating a user recipe to send the sessionToken
in the following operations so they will be executed in the behavior of this user. You can also use the logging in recipe to log in the user by using the defined credentials and the logging out recipe to destroy the sessionToken
.
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| mutation SignUp{
signUp(input: {
fields: {
username: "somefolk"
password: "somepassword"
}
}){
viewer{
user{
id
createdAt
}
sessionToken
}
}
}
|
Result Parse 4.2.0 and later:
1
2
3
4
5
6
7
8
9
10
11
12
13
| {
"data": {
"signUp": {
"viewer": {
"user": {
"id": "X1VzZXI6ckZWbDR3YlJucA==",
"createdAt": "2020-02-06T13:38:04.517Z"
},
"sessionToken": "r:3233bc3b6801a15bcda39ff250416143"
}
}
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| mutation SignUp{
signUp(input: {
userFields: {
username: "somefolk"
password: "somepassword"
}
}){
viewer{
user{
id
createdAt
}
sessionToken
}
}
}
|
Result Parse 3.10.0:
1
2
3
4
5
6
7
8
9
10
11
12
13
| {
"data": {
"signUp": {
"viewer": {
"user": {
"id": "X1VzZXI6UHNOUkJ3Y1YyRQ==",
"createdAt": "2020-02-06T13:38:04.517Z"
},
"sessionToken": "r:c7abf06d951e8087c00fa66d546d1fea"
}
}
}
}
|
1
2
3
4
5
6
7
8
9
10
| mutation SignUp{
signUp(fields:{
username: "somefolk"
password: "somepassword"
}){
id
createdAt
sessionToken
}
}
|
Result Parse 3.9.0:
1
2
3
4
5
6
7
8
9
| {
"data": {
"signUp": {
"id": "Gx2zW7yEnY",
"createdAt": "2019-11-04T14:24:21.333Z",
"sessionToken": "r:6d5f75f0f2d9ee16077b0a0ff1e20eb2"
}
}
}
|
1
2
3
4
5
6
7
8
9
| mutation SignUp{
signUp(fields:{
username: "somefolk"
password: "somepassword"
}){
objectId
createdAt
}
}
|
Result Parse 3.8.0:
1
2
3
4
5
6
7
8
9
| {
"data": {
"signUp": {
"objectId": "KTznKVzto2",
"createdAt": "2019-11-04T14:23:46.014Z",
"sessionToken": "r:2ca6914312ed16803cf3769a25934cdc"
}
}
}
|
1
2
3
4
5
6
7
8
9
| mutation SignUp {
users {
signUp(fields: { username: "somefolk", password: "somepassword" }) {
objectId,
createdAt,
sessionToken
}
}
}
|
Result Parse 3.7.2:
1
2
3
4
5
6
7
8
9
10
11
| {
"data": {
"users": {
"signUp": {
"objectId": "NyU1lNlhPd",
"createdAt": "2019-07-29T09:09:58.222Z",
"sessionToken": "r:a86665f0b63d9d8f945e4b0f302a1655"
}
}
}
}
|