Reputation: 1640
How to check if my Graphql server is down. Currently I make a query on the server using QueryResult and if I get an error I record it. I want to make sure that graphql is up and running before making a query. Is there any way of checking the same in react js. Thank you.
Upvotes: 0
Views: 2057
Reputation: 1640
It looks like there is no solution to know if the grapphql server is down without hitting a query. We should though not the server with multiple queries, but make the first query and according to the response we get we should hit our other queries in the application. We can use network and graphql error to handle error scenarios.
Upvotes: 0
Reputation: 84687
You can add a field to your Query type for that purpose like status
, ping
, etc.
type Query {
status: String!
}
And then query your server like normal to determine if the server is available:
query {
status
}
The request will simply fail if the server is down and you can display whatever messaging accordingly. You can expand on this approach and send down additional information as well. For example, if your server is up but in maintenance, you can return a message to that effect.
Upvotes: 2