Can't run EntityGraphQL endpoint from virtual directory in IIS

49 views Asked by At

I'm using EntityGraphql https://entitygraphql.github.io/ But I can't get it to work if my app is deployed in a virtual folder in IIS

This Works: (doesn't work either)

http://server/service

This does not work:

http://server/services/service

Altair UI and app client fails with a 400 bad request, but no specific error

program.cs:

...
builder.Services.AddGraphQLSchema<Db>(MyNamespace.Web.Schema.AddGraphQlOptions);
...
app.UseEndpoints(routeBuilder =>
{
    routeBuilder.MapControllers();

    routeBuilder.MapGraphQL<Db>();//fails
    routeBuilder.MapGraphQL<Db>(path:"services/service/graphql");//fails
    routeBuilder.MapGraphQL<Db>(path: "/services/service/graphql");//fails

    routeBuilder.MapGraphQLAltair(new AltairOptions
    {
        GraphQLEndPoint = PathString.FromUriComponent("/services/service/graphql")
    });
});
...

Using ASP.NET 6 in IIS 10 EntityGraphQL 5.1.1 enter image description here

EDIT

The question is wrong, it doesn't work with any path, virtual folder or not, it fails with a 400, tried to use a direct path and got:

enter image description here

It's trying to reach a CDN library, my server does not have access to internet, how does this affect?

1

There are 1 answers

0
The One On

It was the connection string

I forgot that EntityGraphQL grabs the conn string directly from the dbcontext configuration

routeBuilder.MapGraphQL<Db>();

In my Db I had a conn string for development dbContext:

  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.EnableSensitiveDataLogging();
            
            optionsBuilder.UseSqlServer(@"Data Source=... bla bla

Make sure you're using the right conn string...