graphql-platform: Querying single types by id partially fails when using Dataloader

First thanks for this awesome project. And let’s come to my weird issue.

Describe the Issue When I try to query single entities from my ef core context using the CacheDataloader the query fails randomly a couple of times and then magically works. This issue only appears when I try to query different entities at a time.

To Reproduce Steps to reproduce the behavior:

  1. Create an EF Core Context with an Entity
  2. Add the Context to asp dependencies using AddDbContext
  3. Add a query to Schema
  4. Query to single entities by id in one query

Code I have this inside my RootQuery Schema

// User
descriptor.Field("user")
    .Argument("id", a => a.Type<NonNullType<IntType>>())
    .Type<UserType>()
    .Resolver( async ctx =>
    {
        var userId = ctx.Argument<int>("id");
        var data = await ctx.CacheDataLoader<int, User>("userById",
            id => ctx.Service<PanelContext>().Users.AsNoTracking()
                .FirstOrDefaultAsync(u => u.Id == userId)).LoadAsync(userId);
        
        return data;
    });

descriptor.Field("app")
    .Argument("id", a => a.Type<NonNullType<IntType>>())
    .Type<AppType>()
    .Resolver( async ctx =>
    {
        var appId = ctx.Argument<int>("id");
        var data = await ctx.CacheDataLoader<int, App>("appById",
            id => ctx.Service<PanelContext>().Apps.AsNoTracking()
                .FirstOrDefaultAsync(a => a.Id == appId)).LoadAsync(appId);
        
        return data;
    });

Here is a gif of this: https://imgur.com/pLumz9N

Not sure what is causing this.

Regards Artur

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

Excellent, I’m looking forward to it! Hot Chocolate and Strawberry Shake rock!

This is now solved with the upcoming resource concept in 10.4