GraphQL Cookbook

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.

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.

Example Parse 3.7.2:
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"
      }
    }
  }
}
Example Parse 3.8:
1
2
3
4
5
6
7
8
9
mutation SignUp{
  signUp(fields:{
    username: "somefolk"
    password: "somepassword"
  }){
    objectId
    createdAt
  }
}
Result Parse 3.8:
1
2
3
4
5
6
7
8
9
{
  "data": {
    "signUp": {
      "objectId": "KTznKVzto2",
      "createdAt": "2019-11-04T14:23:46.014Z",
      "sessionToken": "r:2ca6914312ed16803cf3769a25934cdc"
    }
  }
}
Example Parse 3.9:
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:
1
2
3
4
5
6
7
8
9
{
  "data": {
    "signUp": {
      "id": "Gx2zW7yEnY",
      "createdAt": "2019-11-04T14:24:21.333Z",
      "sessionToken": "r:6d5f75f0f2d9ee16077b0a0ff1e20eb2"
    }
  }
}
Example Parse 3.10:
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:
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"
      }
    }
  }
}