< Summary

Information
Class: Server.Startup
Assembly: Server
File(s): /home/runner/work/NGql/NGql/src/Server/Startup.cs
Line coverage
100%
Covered lines: 36
Uncovered lines: 0
Coverable lines: 36
Total lines: 69
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ConfigureServices(...)100%11100%
Configure(...)100%22100%

File(s)

/home/runner/work/NGql/NGql/src/Server/Startup.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Threading.Tasks;
 3using GraphQL;
 4using GraphQL.Execution;
 5using Microsoft.AspNetCore.Builder;
 6using Microsoft.AspNetCore.Hosting;
 7using Microsoft.Extensions.DependencyInjection;
 8using Microsoft.Extensions.Hosting;
 9using Microsoft.Extensions.Logging;
 10using Server.Data;
 11using Server.Schema;
 12
 13namespace Server;
 14
 15[SuppressMessage("Style", "S2325:Methods and properties that don't access instance data should be static")]
 16public class Startup
 17{
 18    // This method gets called by the runtime. Use this method to add services to the container.
 19    public void ConfigureServices(IServiceCollection services)
 20    {
 921        services.AddControllers();
 922        services
 923            .AddSingleton<IUsersRepository, UsersRepository>()
 1824            .AddMediatR(c => c.RegisterServicesFromAssemblyContaining<Startup>());
 25
 926        services
 927            .AddGraphQL(b => b
 928                .AddSchema<DemoSchema>()
 929                .AddSystemTextJson()
 930                .AddErrorInfoProvider(opt => opt.ExposeExceptionDetailsMode = ExposeExceptionDetailsMode.Message)
 931                .AddGraphTypes(typeof(DemoSchema).Assembly) // Add all IGraphType implementors in the assembly which Dem
 932                .ConfigureExecutionOptions(options =>
 933                {
 4834                    options.EnableMetrics = true;
 935                    // Unhandled exception delegate will be set in Configure method with proper DI
 5736                })
 937            );
 938    }
 39
 40    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 41    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
 42    {
 43        // Configure GraphQL unhandled exception handling with injected logger
 944        var executionOptions = app.ApplicationServices.GetRequiredService<Microsoft.Extensions.Options.IOptions<Executio
 945        executionOptions.Value.UnhandledExceptionDelegate = ctx =>
 946        {
 347            logger.LogError("{Error} occurred", ctx.OriginalException.Message);
 348            return Task.CompletedTask;
 949        };
 50
 951        if (env.IsDevelopment())
 52        {
 953            app.UseDeveloperExceptionPage();
 54        }
 55
 956        app.UseHttpsRedirection();
 57
 958        app.UseRouting();
 59
 960        app.UseEndpoints(endpoints =>
 961        {
 962            // map HTTP middleware for schema at the default path /graphql
 963            endpoints.MapGraphQL<DemoSchema>();
 964
 965            // map ui
 966            endpoints.MapGraphQLGraphiQL("/");
 1867        });
 968    }
 69}