< Summary

Information
Class: Server.Startup
Assembly: Server
File(s): /home/runner/work/NGql/NGql/src/Server/Startup.cs
Line coverage
94%
Covered lines: 34
Uncovered lines: 2
Coverable lines: 36
Total lines: 69
Line coverage: 94.4%
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%2289.47%

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    {
 621        services.AddControllers();
 622        services
 623            .AddSingleton<IUsersRepository, UsersRepository>()
 1224            .AddMediatR(c => c.RegisterServicesFromAssemblyContaining<Startup>());
 25
 626        services
 627            .AddGraphQL(b => b
 628                .AddSchema<DemoSchema>()
 629                .AddSystemTextJson()
 630                .AddErrorInfoProvider(opt => opt.ExposeExceptionDetailsMode = ExposeExceptionDetailsMode.Message)
 631                .AddGraphTypes(typeof(DemoSchema).Assembly) // Add all IGraphType implementors in the assembly which Dem
 632                .ConfigureExecutionOptions(options =>
 633                {
 4834                    options.EnableMetrics = true;
 635                    // Unhandled exception delegate will be set in Configure method with proper DI
 5436                })
 637            );
 638    }
 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
 644        var executionOptions = app.ApplicationServices.GetRequiredService<Microsoft.Extensions.Options.IOptions<Executio
 645        executionOptions.Value.UnhandledExceptionDelegate = ctx =>
 646        {
 047            logger.LogError("{Error} occurred", ctx.OriginalException.Message);
 048            return Task.CompletedTask;
 649        };
 50
 651        if (env.IsDevelopment())
 52        {
 653            app.UseDeveloperExceptionPage();
 54        }
 55
 656        app.UseHttpsRedirection();
 57
 658        app.UseRouting();
 59
 660        app.UseEndpoints(endpoints =>
 661        {
 662            // map HTTP middleware for schema at the default path /graphql
 663            endpoints.MapGraphQL<DemoSchema>();
 664
 665            // map ui
 666            endpoints.MapGraphQLGraphiQL("/");
 1267        });
 668    }
 69}