-
-
Notifications
You must be signed in to change notification settings - Fork 722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort with Variables tries to instantiate an object from the target collection, fails if no parameterless constructor available #6545
Comments
The issue still persists with version 13.5.1; I made a showcase application in https://github.com/alex-mazzariol/hotchocolate-issue-6545. If anybody can point me in the right direction, since I also noticed some recent work around the classes that digest the variable values, I might be even able to find the problem and propose a fix... |
As far as I can gather debugging, it seems like the VariableCoercionHelper asks the InputParser to convert the variables into the appropriate input type, but for some reason, when it comes to mapping the added field (inside InputParser.ParseObject) the type from the |
I've been able to find and, apparently, solve the issue - inside
The issue is in the call to If I replace the parameter with
And build HotChocolate again, I am able to sort (correctly) with the input type applied to the correct field, and can continue sorting by the other existing fields as well. Could someone verify the one-line fix with the tests? I am unable to find instructions on how to run them, and opening a PR for a oneliner might be a little too complex for the result. |
Is there an existing issue for this?
Product
Hot Chocolate
Describe the bug
I have a business backend that deals, among other entities, with subjects and their addresses. In the database, handled via Entity Framework Core 7, there is a relation between the subject and its addresses, so that inside the Subject entity there is an "Addresses" navigation property which is defined as an ICollection
. Both classes have no parameterless constructor to fill non-nullable property values.When returning an IQueryable to HotChocolate, I have the query set up like this:
The readRepository wraps and ultimately returns the DbSet from Entity Framework, just mixing in a .Where condition on the DeletionDate field.
For the purpose of the bug, I don't think filtering middleware is an issue; the sorting middleware is configured with these settings:
In this way, a virtual "legalResidentialAddress" field is added to the GraphQL schema, and it is supposed to be able to be used for sorting.
Indeed when the query is like this:
the expected results are received.
But when the query includes variables, like this:
An exception is raised and no errors are returned. Exception details and stacktrace is below.
I don't expect the difference between using and not using variables to produce the instantiation of an object from the target class of the sorting collection; why is it happening? Is a parameterless constructor actually needed?
Steps to reproduce
Due to the complexity of producing a sample showcase github repo, it will be added if the above description is not enough to understand the issue clearly.
Relevant log output
Additional Context?
No response
Version
13.2.1
The text was updated successfully, but these errors were encountered: