Skip to main content

User Queries

Queries for retrieving user information.

user​

Retrieves a single user by ID.

Arguments​

type UserArgs {
"""
ID of the user to retrieve.
"""
id: Int!
}

Response​

type User {
"""
Unique identifier for the user.
"""
id: Int!

"""
User's name.
"""
name: String!

"""
User's email address.
"""
email: String!

"""
List of client IDs this user has access to.
"""
client_list: [Int!]
}

Example Query​

query GetUser {
user(id: 123) {
id
name
email
client_list
}
}

currentUser​

Retrieves the currently authenticated user based on the JWT token.

Arguments​

None - this query uses the JWT token from the request to identify the current user.

Response​

type User {
"""
Unique identifier for the user.
"""
id: Int!

"""
User's name.
"""
name: String!

"""
User's email address.
"""
email: String!

"""
List of client IDs this user has access to.
"""
client_list: [Int!]

"""
User roles for permission management.
"""
roles: [String!]
}

Example Query​

query GetCurrentUser {
currentUser {
id
name
email
client_list
roles
}
}

This query is particularly useful for checking the current user's permissions, including whether they have the admin role required for certain operations like updating tracker locations.

users​

Retrieves all users.

Example Query​

query GetUsers {
users {
id
name
email
client_list
}
}

Error Handling​

Common Errors​

Error CodeDescription
USER_NOT_FOUNDUser ID not found
PERMISSION_DENIEDNot authorized to view user
UNAUTHORIZEDNo valid JWT token provided
NOT_AUTHENTICATEDJWT token is invalid or expired

Example Error Response​

{
"errors": [
{
"message": "User not found",
"extensions": {
"code": "USER_NOT_FOUND",
"userId": "123"
}
}
]
}

Best Practices​

  1. Authentication

    • Always include valid JWT with client_list claim
    • Handle token expiration gracefully
  2. Performance

    • Request only needed fields
    • Consider caching strategies
  3. Security

    • Protect personal data
    • Log access attempts
    • Rate limit operations
  4. Error Handling

    • Handle all error cases gracefully
    • Provide meaningful error messages
    • Implement retry logic where appropriate