ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.2k stars 743 forks source link

UseSorting on descriptors fail if the descriptor uses async #6252

Open larsbloch opened 1 year ago

larsbloch commented 1 year ago

Is there an existing issue for this?

Product

Hot Chocolate

Describe the bug

I have a post in General on the slack channel where a workaround was provided https://hotchocolategraphql.slack.com/archives/CD9TNKT8T/p1686204368383929

I get an error when i want to add sorting to a field using a descriptor. This only happens when its async

Example (this fails)

descriptor.Field("networks")
    .Type<NonNullType<ListType<NetworkType>>>()
    .Resolve(async ctx =>
            {
                var dataloader = ctx.Service<INetworksForUserDataLoader>();
                var result = (await dataloader.LoadAsync(ctx.Parent<PlatformUser>().Id)).AsEnumerable();
                var checkSort = ctx.ArgumentKind("order") == ValueKind.Null ? Sort.None : Sort.Specified;

                if (checkSort == Sort.None)
                    result = result.OrderByDescending(x => x.Name);

                return result;
            }).UseSorting();

Does not work with UseSorting // Does work with useSorting .Resolve(async ctx => // .Resolve( ctx =>

Im not familiar with the internals but Anton on slack provided this feedback and an example of a quick fix I think it's because the async Resolve overload doesn't save the result type. In the implementation, they use NativeType, which is internal, to make it imply the type on its own. You can get it with reflection and pass it manually.

This is the error shown in visual studio image

Steps to reproduce

  1. Have an descriptor on an entity which resolves using async.
  2. Add UseSorting to the descriptor
  3. Start api

Relevant log output

No response

Additional Context?

No response

Version

13.2

bardhyliis commented 1 year ago

Do you guys have any release on mind on when will this be fixed?