GraphQL Cookbook

Getting a logged user through the Parse GraphQL API

Problem

You want to get a logged user’s data from your backend through the Parse GraphQL API.

Solution

Using the Parse GraphQL API, you can get a logged user’s data just by sending the user’s sessionToken through the X-Parse-Session-Token header (as described in the authenticating a user recipe) and calling the me query.

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
10
11
query Me {
  users {
    me {
      objectId,
      createdAt,
      updatedAt,
      username,
      sessionToken
    }
  }
}
Result Parse 3.7.2:
1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "data": {
    "users": {
      "me": {
        "objectId": "NyU1lNlhPd",
        "createdAt": "2019-07-29T09:09:58.222Z",
        "updatedAt": "2019-07-29T09:09:58.222Z",
        "username": "somefolk",
        "sessionToken": "r:cbca71d29d7601761b48ed01bbe9638d"
      }
    }
  }
}
Example Parse 3.8:
1
2
3
4
5
6
query Me{
  viewer {
    sessionToken
    username
  }
}
Result Parse 3.8:
1
2
3
4
5
6
7
8
{
  "data": {
    "viewer": {
      "sessionToken": "r:5c5024921339edf773b5b3e867d708be",
      "username": "somefolk"
    }
  }
}
Example Parse 3.9:
1
2
3
4
5
6
7
8
9
10
11
query Me {
  users {
    me {
      objectId,
      createdAt,
      updatedAt,
      username,
      sessionToken
    }
  }
}
Result Parse 3.9:
1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "data": {
    "users": {
      "me": {
        "objectId": "NyU1lNlhPd",
        "createdAt": "2019-07-29T09:09:58.222Z",
        "updatedAt": "2019-07-29T09:09:58.222Z",
        "username": "somefolk",
        "sessionToken": "r:cbca71d29d7601761b48ed01bbe9638d"
      }
    }
  }
}

AQUI

Example Parse 3.10:
1
2
3
4
5
6
7
8
9
10
11
query Me {
	viewer {
    user{
      id
      createdAt
      updatedAt
      username
    }
    sessionToken
  }
}
Result Parse 3.10:
1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "data": {
    "viewer": {
      "user": {
        "id": "X1VzZXI6UHNOUkJ3Y1YyRQ==",
        "createdAt": "2020-02-06T13:38:04.517Z",
        "updatedAt": "2020-02-06T13:38:04.517Z",
        "username": "somefolk"
      },
      "sessionToken": "r:00afa413b9cadd1007ad9ccd3c00f1c9"
    }
  }
}