cajuncoding / GraphQL.RepoDB

A set of extensions for working with HotChocolate GraphQL and Database access with micro-orms such as RepoDb (or Dapper). This extension pack provides access to key elements such as Selections/Projections, Sort arguments, & Paging arguments in a significantly simplified facade so this logic can be leveraged in the Serivces/Repositories that encapsulate all data access (without dependency on IQueryable and execution outside of the devs control).
MIT License
40 stars 5 forks source link

Fix for bug when attempting to Cursor Slice an empty result set #7

Closed davidjamesb closed 2 years ago

davidjamesb commented 2 years ago

When no results are returned by an underlying data source (e.g. empty list/table, etc) IEnumerableCursorPagingCustomExtensions.SliceAsCursorPage() creates a new CursorPageSlice and passes null for the results parameter. This causes an ArgumentException to be thrown by the CursorPageSlice constructor.

This bug was discovered when testing a resolver over a postgresql table I had just created but contained no rows. The GraphQL query should return an empty node collection and totalCount = 0.

Relevant line for the bug:

https://github.com/cajuncoding/GraphQL.RepoDB/blob/52dabefdeec5f6d29e4f97c3a927bc05426ac31c/GraphQL.PreProcessingExtensions/Paging/CursorPaging/IEnumerableCursorPagingCustomExtensions.cs#L45

This can be reproduced by modifying Tests.StarWarsCharacterResolver.CreateCharacters to return an empty list and running the TestParamsContextCursorPagingOnlyFirst test.

This PR modifies behavior this by:

cajuncoding commented 2 years ago

Thanks for the details, I’ll take a look at the info provided this week!

The PR for the proposed fix is most appreciated!

cajuncoding commented 2 years ago

Ok, Merged, pulled, and re-ran tests . . . new test coverage is passing as expected (was definitely failing before).

This now resolves issue #8 👍!

image

I'll push a minor update to Nuget soon!