Hotchocolate graphql localhost not working when the hotchocolate banan cale pop tool is idle for a longer duration

219 Views Asked by At

I'm trying to develop a Hotchocolate GraphQL API of version 13.5.0 on .net core V 8.0.1. The app runs fine on the first debug and later when the app tool (banana cake pop) is kept idle for a long duration I get below error screen.

img3

Below are the details from developer tool.

img4

My Program.cs file code is as below,

using igraphql.api.Schema.Queries;
using GraphQL.Server.Ui.Voyager;
using NLog.Web;
using NLog;

const string ALLOWED_ORIGINS = "OriginPolicy";
var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
logger.Debug("init main");

var builder = WebApplication.CreateBuilder(args);
{
    builder.Services.AddHealthChecks();

    builder.Logging.ClearProviders();
    builder.Logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
    builder.Host.UseNLog();

    try
    {
        builder.Services.AddAuthorization();

        builder.Services.AddCors(options =>
        {
            options.AddPolicy(ALLOWED_ORIGINS, policy =>
            {
                policy.WithOrigins(Environment
                        .ExpandEnvironmentVariables(builder.Configuration.GetValue<string>("Orgins:AllowedOrgins")!)
                        .Split(',', System.StringSplitOptions.RemoveEmptyEntries))
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials();
            });
        });

        builder.Services.AddHttpContextAccessor();
        builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

        builder.Services.AddGraphQLServer()
            .AddAuthorization()
            //.AddGlobalObjectIdentification()
            .RegisterService<IHttpContextAccessor>()
            .AddQueryType<Query>()
            .AddTypeExtension<TokensQuery>()
            .AllowIntrospection(builder.Environment.IsDevelopment())
            .InitializeOnStartup();
    }
    catch (Exception exception)
    {
        // NLog: catch setup errors
        logger.Error(exception, "Internal Server Error - On server load.");
        throw;
    }
    finally
    {
        // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
        LogManager.Shutdown();
    }
}

var app = builder.Build();
{
    app.UseCookiePolicy(new CookiePolicyOptions
    {
        Secure = CookieSecurePolicy.Always,
    });

    app.UseCors(ALLOWED_ORIGINS);

    app.UseHttpsRedirection();
    
    app.UseAuthentication();

    app.UseRouting();

    app.UseAuthorization();

    app.UseGraphQLVoyager(options: new VoyagerOptions()
    {
        GraphQLEndPoint = "/graphql",
    }, path: "/voyager");
    
    app.MapGraphQL();

    app.MapHealthChecks("/health").AllowAnonymous();

    try
    {
        using (var listener = app.RunAsync())
        {
            logger.Info("GraphQL API server initialized");
            await listener;
        }
    }
    catch (Exception ex)
    {
        logger.Error(ex, "Error at init");
    }
    finally
    {
        // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
        LogManager.Shutdown();
    }
}

LaunchSettings.json

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:22447",
      "sslPort": 44300
    }
  },
  "profiles": {
    "GraphQL.API": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchUrl": "graphql",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7052;http://localhost:5234",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "graphql",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

  1. Tried changing localhost port number. But didn't work.
  2. Tried executing on different browser. But didn't work.
  3. Works good in Insomnia but not in Banana Cake pop.

img1

img2

0

There are 0 best solutions below