0

I'm new to HotChocolate and graphql but this issue that I have at the moment with HotChocolate is a bit strange.

So I'm using the following packages in a dotnet 6.0 webapi project:

  1. HotChocolate.AspNetCore @ 12.5.0
  2. HotChocolate.AspNetCore.Authorization @ 12.5.0
  3. HotChocolate.Data @ 12.5.0
  4. HotChocolate.Types.Scalars @ 12.5.0

I have a query like beloew

    public IQueryable<EmploymentContract> GetEmploymentContracts([Service] ApplicationDbContext dbContext)
        => dbContext.EmploymentContracts
            .Include(x => x.Person)
            .Include(x => x.Organisation)
            .Include(x => x.Department);

and then a descriptor for it like

        descriptor.Field(x => x.GetEmploymentContracts(_dbContext))
            .UsePaging(options: new PagingOptions { DefaultPageSize = PAGE_SIZE, IncludeTotalCount = true })
            .UseFiltering()
            .UseSorting();

Now the issue is that if I run a query like below, it takes even sometimes more than 30 seconds to give back the results. I checked the ef core generated sql query and that runs in mssql in 200ms. Whatever is slowing down the request, is happening after ef core runs the query and gets the result from the database.

{
    employmentContracts {
        nodes {
            personnelNumber
        }
    }
}

As you see, the above query is really simple.

When I remove the UsePaging it works fine and I get the results immediately.

But if not, it either will give a timeout or will run for 22s or so...

Edit

The problem is solved and the issue was not with GraphQL. The model had some images stored in places where the query was happening. The model is changed and the issue is not happening anymore.

Farhad Nowzari
  • 79
  • 2
  • 11
  • It sounds like your data is pulled in memory and sliced there. Can you create a small repro and create a github issue. – Michael Ingmar Staib Mar 23 '22 at 09:43
  • On the ef core sql query, it is creating the query with ` take (@variable) ` statement. I will create a repo – Farhad Nowzari Mar 23 '22 at 09:49
  • Probably you have a lot of records. Try measure `GetEmploymentContracts(ctx).Count()` – Svyatoslav Danyliv Mar 23 '22 at 10:52
  • @SvyatoslavDanyliv, I only have two records. That is why it is strange to me. I'm creating a repo. The model is a bit complicated though. But will see if it will also happen in the simplified version, if not I may be able to compare them and see what is different. – Farhad Nowzari Mar 23 '22 at 11:57
  • @MichaelIngmarStaib, I did a simpler project and saw the problem it is not an issue with HotChocolate. The problem is that the Person in EmploymentContract has a navigation to an Image entity. I removed this navigation apparetnly HotChocolate was traversing in it. Either this was the issue or that image was being stored on the contract because the contract stores a json copy of the time the person has received the contract. But now it is perfect. Thanks :) – Farhad Nowzari Mar 23 '22 at 13:23

0 Answers0