Skip to content
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

Add record struct support for sort #7166

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

zyofeng
Copy link

@zyofeng zyofeng commented Jun 13, 2024

Summary of the changes (Less than 80 chars)

Add support for record struct sortconvention

@PascalSenn
Copy link
Member

@zyofeng I dont think this works as this would also treat structs like Guid as a sortable input object. Does it work when you just manually register the SortInputType?

@zyofeng
Copy link
Author

zyofeng commented Jun 13, 2024

You are correct, I've updated the PR to filter out structs such as guid, decimal by checking for PrintMembers method, which is a generated method specifically for record structs

@glen-84 glen-84 changed the title add record struct support for sort Add record struct support for sort Jun 18, 2024
@PascalSenn
Copy link
Member

@zyofeng How does one of you sort queries look like?

@zyofeng
Copy link
Author

zyofeng commented Jul 5, 2024

I have the following record struct

public record struct CountryDto(string Name, string? Iso, string State, bool IsNonCompliantCountry);

using the updated sortconvention I am able to sort using this query

query {
  countries(order: [{ name: ASC }, { isNonCompliantCountry: DESC }]) {
    isNonCompliantCountry
    iso
    name
    state
  }
}

and generate the following EF Core query

SELECT [c].[IsNonCompliantCountry], [c].[Iso], [c].[Name], [c].[State]
FROM [Countries] AS [c]
ORDER BY [c].[Name], [c].[IsNonCompliantCountry] DESC

since IsNonCompliantCountry is a boolean struct this means the modified SortConvention works for normal struct.

@zyofeng
Copy link
Author

zyofeng commented Aug 12, 2024

Is this looking okay?

@michaelstaib
Copy link
Member

michaelstaib commented Aug 15, 2024

This one needs tests for this otherwise we cannot verify if this is a good idea or not. We need tests showing that Guid and other important structs are ignored. What is with typed id structs ... they are not primitives.

@michaelstaib michaelstaib marked this pull request as draft August 15, 2024 14:25
@michaelstaib michaelstaib self-requested a review August 15, 2024 14:26
@michaelstaib
Copy link
Member

@zyofeng Are you still working on this?

@zyofeng
Copy link
Author

zyofeng commented Aug 18, 2024

@zyofeng Are you still working on this?

Im happy to take a look at implementing some tests for record struct vs common struct types like guid, datetime etc when I get some time, hopefully this weekend.

@zyofeng
Copy link
Author

zyofeng commented Aug 20, 2024

I've added some tests for common struct types as well as custom sort type convention, let me know if this is sufficient.

@zyofeng zyofeng marked this pull request as ready for review August 22, 2024 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants