Skip to content

fiakkasa/GraphHealthChecks

Repository files navigation

GraphHealthChecks

NuGet Version NuGet Downloads License: MIT

Graph Health Checks for HotChocolate.

The purpose of this middleware is to provide feedback in regards to the health of the schema.

Nuget

Note

There appears to be a compatibility issue for projects targeting .NET 7 and assembly Assembly Microsoft.Extensions.Hosting, Version=7.0.0.0 and more specifically OptionsBuilderExtensions.ValidateOnStart resulting in error:

The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.OptionsBuilderExtensions.ValidateOnStart(Microsoft.Extensions.Options.OptionsBuilder)' and 'Microsoft.Extensions.DependencyInjection.OptionsBuilderExtensions.ValidateOnStart(Microsoft.Extensions.Options.OptionsBuilder)'

Until resolved please consider using a previous version of the package targeting .NET 7.

Usage

Locate the services registration and append one of:

  • .AddGraphHealthWithNoLogger - use when no logging is required
  • .AddGraphHealthWithILogger - use when the ILogger provider is available
  • .AddGraphHealthWithILoggerFactory - use when the ILoggerFactory provider is available

⚠️ Bear in mind that IHealthChecksBuilder needs to be appended before any of the aforementioned.

ex.

// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
    // ...
    services
        .AddHealthChecks()
        .AddGraphHealthWithILogger();
    // ...
}

📝 If further customization is required, consider wiring up any of the factories manually or use the GraphHealthCheck class itself as required.

If separate schemas are present, multiple registrations can be done for each schema.

ex.

// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
    // ...
    services
        .AddHealthChecks()
        .AddGraphHealthWithILogger(healthName: "health1", schemaName: "schema1")
        .AddGraphHealthWithILogger(healthName: "health2", schemaName: "schema2");
    // ...
}