ChilliCream / ChilliCream/graphql-platform
UseSorting on descriptors fail if the descriptor uses async
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
Description
Is there an existing issue for this?
- I have searched the existing issues
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
Steps to reproduce
- Have an descriptor on an entity which resolves using async.
- Add UseSorting to the descriptor
- Start api
Relevant log output
No response
Additional Context?
No response
Version
13.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure in Hot Chocolate 13.2 with an async descriptor resolver followed by UseSorting, using the example in the issue. Trace the async Resolve overload and sorting setup to determine why the result type is unavailable; done means the same descriptor starts successfully and sorting works without a workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, graphql
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100