question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use Hot Chocolate sorting

See original GitHub issue

Not sure if this is the same issue that I mentioned in #11 as being obscured, but it seems like it. In the first case, it was calling a mutation with a complex parameter and the same is in this case. All both of these issues could very well be syntax errors on my part, but I can’t figure it out after much review of your documentation.

So, I’m simplified this problem down as much as possible and created a repo that reproduces the issue. I’ve made a GraphQL test server that just exposes a simple Author class and has a query to get a list of authors. I added Hot Chocolate’s sorting attribute on it. Anyhow, I cannot get the ZeroQL client to compile when trying to provide a sorting criteria.

var sortResponse = await qlClient.Query(static query => query.Authors(new AuthorSortInput[] { new AuthorSortInput { Name = SortEnumType.Asc } }, o => o.Name));

REF: https://github.com/Servant-Software-LLC/ZeroQL_Can_Not_Sort_Hot_Chocolate/blob/master/Integration.Tests/UnitTest1.cs#L29

If I don’t provide a sorting argument, then it compiles and runs in the Test Explorer just fine:

var noSortResponse = await qlClient.Query(static query => query.Authors(null, o => o.Name));

If you clone the repo at https://github.com/Servant-Software-LLC/ZeroQL_Can_Not_Sort_Hot_Chocolate, it has the GraphQL server, generator and XUnit test which doesn’t compile in the latest commit.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
DaveRMaltbycommented, Nov 2, 2022

@byme8, Wonderful! I now have a working solution whose unit tests pass. Converting the variable json strings values were a blocker for a long while, but I found that Hot Chocolate provides an IHttpRequestParser service that I could make use of to get the proper variables dictionary instance.

Anyhow, I’ve push the latest commit https://github.com/Servant-Software-LLC/ZeroQL_Can_Not_Sort_Hot_Chocolate/commit/ef366f7b709ad8bd435d3853ddf0ed97d56bb073 to the repo in case anyone else comes across this and needs an example of integration tests that don’t need an HTTP endpoint stood up in order for them to execute against their GraphQL server.

Thanks again, David

1reaction
byme8commented, Nov 2, 2022

To pass complex objects, you have to use the input variables. It is essential to do it like that because there is no direct mapping from complex object to graphql literal.

var variables = new { Sorting = new AuthorSortInput[] { new AuthorSortInput { Name = SortEnumType.Asc } } };
var sortResponse = await qlClient.Query(variables, static (input, query) => query.Authors(input.Sorting, o => o.Name));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sorting - Hot Chocolate
Under the hood, sorting is based on top of normal Hot Chocolate input types. You can easily customize them with a very familiar...
Read more >
Sort by resolved property in HotChocolate
I tried to set up a SortInputType<T> -derived class and on the Configure method explicitly mention my resolved field as: descriptor.
Read more >
Unable to resolve service for type 'HotChocolate. ...
works for me! Only i was setting filters explicity before (BindFiltersExplicitly) but not sure how this will work. Also sorting not sure how....
Read more >
Adding Sorting to a Hot Chocolate 13 GraphQL API - YouTube
Your browser can't play this video. Learn more.
Read more >
Say hello to Hot Chocolate 12! (GraphQL in .NET) : r/dotnet
'Hot Chocolate is not bound to a specific database, pattern or architecture.' - Except out of the box - it is bound to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found