GraphQL-based connection status checker for application-level connectivity validation.
More...
GraphQL-based connection status checker for application-level connectivity validation.
CSimpleConnectionCheckerComp implements IConnectionStatusProvider using the GraphQL client infrastructure to validate full-stack connectivity. Unlike CAsyncConnectionCheckerComp which only tests HTTP-level connectivity, this component validates the entire application protocol stack including network, authentication, and GraphQL query execution.
This component extends imtclientgql::CClientRequestManagerCompBase, leveraging the GraphQL client framework to perform real application-level health checks. It's ideal for validating that not just the network is working, but the entire service pipeline is operational and responsive.
Key Features
Application-Level Validation:
- Tests complete request pipeline (network + auth + GraphQL)
- Validates actual application protocols, not just HTTP
- Detects authentication failures
- Confirms GraphQL endpoint accessibility
GraphQL Integration:
- Extends CClientRequestManagerCompBase
- Uses GraphQL client for requests
- Supports configurable GraphQL commands
- Leverages existing GraphQL infrastructure
Status Management:
- Three states: CS_UNKNOWN, CS_DISCONNECTED, CS_CONNECTED
- Observable status via IChangeable
- Updated based on GraphQL request success/failure
Command Configuration:
- Configurable GraphQL command ID
- Flexible query selection
- Typically uses lightweight introspection or health queries
Architecture
|
| extends
v
CClientRequestManagerCompBase
|
| uses
v
GraphQL Client Infrastructure
|
+--------+--------+
| |
v v
Network Layer Auth Layer
| |
+--------+--------+
|
v
GraphQL Endpoint
|
v
Update m_status based on
success/failure
GraphQL-based connection status checker for application-level connectivity validation.
Component Attributes
| Attribute | Type | Description | Required |
| Command-ID | QByteArray | GraphQL command identifier for health check query | Yes |
The Command-ID typically refers to a lightweight GraphQL query such as:
- Introspection query (__schema)
- Health check query (healthCheck, ping, status)
- Simple scalar query (serverTime, version)
Comparison with CAsyncConnectionCheckerComp
| Aspect | CAsyncConnectionCheckerComp | CSimpleConnectionCheckerComp |
| Check Method | HTTP GET request | GraphQL query execution |
| What It Tests | HTTP connectivity only | Full application stack |
| Use Case | Basic network availability | Application health validation |
| Dependencies | QNetworkAccessManager | GraphQL client infrastructure |
| Authentication | Not tested | Validated as part of request |
| Protocol | Generic HTTP | Application-specific GraphQL |
| Failure Detection | Network/HTTP errors | Auth + GraphQL + network errors |
| Overhead | Low | Moderate (full request pipeline) |
Status Determination Logic
CS_CONNECTED:
- GraphQL query executed successfully
- Authentication succeeded (if required)
- Network connection established
- Valid GraphQL response received
CS_DISCONNECTED:
- Network unreachable
- Authentication failed
- GraphQL query failed
- Timeout or connection error
- Invalid response format
CS_UNKNOWN:
- Initial state before first request
- After component reset
Usage Examples
Basic Usage
auto checker = icomp::CreateComponent<CSimpleConnectionCheckerComp>();
checker->SetAttributeValue("Command-ID", "HealthCheckQuery");
QObject::connect(checker.get(), &IChangeable::OnChanged,
[checker](const IChangeable::ChangeSet&) {
auto status = checker->GetConnectionStatus();
if (status == IConnectionStatusProvider::CS_CONNECTED) {
qDebug() << "Application service is healthy";
qWarning() << "Application service is unavailable";
}
});
@ CS_DISCONNECTED
Connection is unavailable or failed health check.
Post-Login Validation
class LoginValidator : public QObject {
Q_OBJECT
public:
LoginValidator() {
m_checker = icomp::CreateComponent<CSimpleConnectionCheckerComp>();
m_checker->SetAttributeValue("Command-ID", "UserProfileQuery");
connect(m_checker.get(), &IChangeable::OnChanged,
this, &LoginValidator::OnValidationComplete);
}
void ValidateSession() {
qDebug() << "Validating authenticated session...";
}
signals:
void sessionValid();
void sessionInvalid();
private slots:
void OnValidationComplete() {
auto status = m_checker->GetConnectionStatus();
if (status == IConnectionStatusProvider::CS_CONNECTED) {
qInfo() << "Session validated successfully";
emit sessionValid();
} else {
qWarning() << "Session validation failed - re-login required";
emit sessionInvalid();
}
}
private:
std::shared_ptr<CSimpleConnectionCheckerComp> m_checker;
};
Service Health Dashboard
class ServiceHealthDashboard : public QObject {
Q_OBJECT
public:
ServiceHealthDashboard() {
m_authChecker = CreateChecker("AuthHealthQuery");
m_dataChecker = CreateChecker("DataHealthQuery");
m_apiChecker = CreateChecker("ApiHealthQuery");
connect(m_authChecker.get(), &IChangeable::OnChanged,
this, &ServiceHealthDashboard::UpdateDashboard);
connect(m_dataChecker.get(), &IChangeable::OnChanged,
this, &ServiceHealthDashboard::UpdateDashboard);
connect(m_apiChecker.get(), &IChangeable::OnChanged,
this, &ServiceHealthDashboard::UpdateDashboard);
}
struct HealthStatus {
bool authService = false;
bool dataService = false;
bool apiService = false;
bool AllHealthy() const {
return authService && dataService && apiService;
}
int HealthyCount() const {
return (authService ? 1 : 0) +
(dataService ? 1 : 0) +
(apiService ? 1 : 0);
}
};
HealthStatus GetHealthStatus() const {
HealthStatus status;
status.authService = IsConnected(m_authChecker);
status.dataService = IsConnected(m_dataChecker);
status.apiService = IsConnected(m_apiChecker);
return status;
}
signals:
void healthStatusChanged(const HealthStatus& status);
private:
std::shared_ptr<CSimpleConnectionCheckerComp> CreateChecker(
const QByteArray& commandId) {
auto checker = icomp::CreateComponent<CSimpleConnectionCheckerComp>();
checker->SetAttributeValue("Command-ID", commandId);
return checker;
}
static bool IsConnected(const std::shared_ptr<CSimpleConnectionCheckerComp>& checker) {
return checker->GetConnectionStatus() == IConnectionStatusProvider::CS_CONNECTED;
}
void UpdateDashboard() {
auto status = GetHealthStatus();
qInfo() << "Service Health:"
<< "Auth:" << (status.authService ? "OK" : "FAIL")
<< "Data:" << (status.dataService ? "OK" : "FAIL")
<< "API:" << (status.apiService ? "OK" : "FAIL");
emit healthStatusChanged(status);
}
std::shared_ptr<CSimpleConnectionCheckerComp> m_authChecker;
std::shared_ptr<CSimpleConnectionCheckerComp> m_dataChecker;
std::shared_ptr<CSimpleConnectionCheckerComp> m_apiChecker;
};
Best Practices
- Lightweight Queries: Use minimal GraphQL queries for health checks
- Introspection: __schema { queryType { name } }
- Simple scalar: { serverTime }
- Health endpoint: { health { status } }
- Avoid heavy queries with joins or complex logic
- Authentication Awareness: Component validates auth as part of request
- Ensure auth tokens are valid before health checks
- Handle authentication failures appropriately
- Refresh tokens if health check fails due to auth
- Complementary Use: Combine with CAsyncConnectionCheckerComp
- CAsync for basic network availability
- CSimple for application-level validation
- Fast network checks + thorough service validation
- Error Handling: Distinguish between network and application errors
- Network errors: likely transient, retry with backoff
- Auth errors: require user intervention
- GraphQL errors: may indicate service degradation
- Check Frequency: Less frequent than network-only checks
- CAsync: 10-30 seconds (network check)
- CSimple: 60-300 seconds (full validation)
- More overhead due to full request pipeline
- Command Registration: Ensure Command-ID references valid query
- Register health check queries in GraphQL schema
- Use dedicated health check resolvers
- Keep health queries read-only (no mutations)
GraphQL Health Check Queries
Introspection Query
# Minimal introspection - verifies GraphQL endpoint
query HealthCheck {
__schema {
queryType {
name
}
}
}
Dedicated Health Endpoint
# Custom health check query
query HealthCheck {
health {
status # "OK" | "DEGRADED" | "ERROR"
version
uptime
timestamp
}
}
Lightweight Data Query
# Simple query to verify data access
query HealthCheck {
serverInfo {
version
timestamp
}
}
Troubleshooting
Always CS_DISCONNECTED:
- Verify Command-ID references a valid GraphQL query
- Check authentication credentials
- Ensure GraphQL client is configured correctly
- Review GraphQL endpoint URL
- Check network connectivity
Inconsistent with Network Status:
- May indicate authentication issues
- GraphQL endpoint may be down while HTTP is up
- Check GraphQL-specific errors in logs
Authentication Failures:
- Validate auth tokens are not expired
- Ensure auth provider is configured
- Check auth headers are sent correctly
- Review auth error responses
- See also
- IConnectionStatusProvider, CAsyncConnectionCheckerComp, CInternetConnectionCheckerComp
-
imtclientgql::CClientRequestManagerCompBase
Definition at line 376 of file CSimpleConnectionCheckerComp.h.