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.

Example:
1
2
3
4
5
6
7
8
9
mutation SignUp {
  users {
    signUp(fields: { username: "somefolk", password: "somepassword" }) {
      objectId,
      createdAt,
      sessionToken
    }
  }
}
Result:
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"
      }
    }
  }
}