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 Code | Description |
|---|---|
USER_NOT_FOUND | User ID not found |
PERMISSION_DENIED | Not authorized to view user |
UNAUTHORIZED | No valid JWT token provided |
NOT_AUTHENTICATED | JWT token is invalid or expired |
Example Error Response
{
"errors": [
{
"message": "User not found",
"extensions": {
"code": "USER_NOT_FOUND",
"userId": "123"
}
}
]
}
Best Practices
-
Authentication
- Always include valid JWT with client_list claim
- Handle token expiration gracefully
-
Performance
- Request only needed fields
- Consider caching strategies
-
Security
- Protect personal data
- Log access attempts
- Rate limit operations
-
Error Handling
- Handle all error cases gracefully
- Provide meaningful error messages
- Implement retry logic where appropriate