Skip to content

ObjectListFilter filter values to target type coercion#589

Merged
xperiandri merged 10 commits into
devfrom
copilot/ObjectListFilter-file-coercion
Jul 9, 2026
Merged

ObjectListFilter filter values to target type coercion#589
xperiandri merged 10 commits into
devfrom
copilot/ObjectListFilter-file-coercion

Conversation

@xperiandri

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Test Results

    3 files      3 suites   10m 16s ⏱️
  515 tests   510 ✅  5 💤 0 ❌
1 545 runs  1 530 ✅ 15 💤 0 ❌

Results for commit 47cf92e.

♻️ This comment has been updated with latest results.

Comment thread tests/FSharp.Data.GraphQL.Tests/ObjectListFilter/TypeCoercionTests.Common.fs Outdated
Comment thread tests/FSharp.Data.GraphQL.Tests/ObjectListFilter/TypeCoercionFilterTests.fs Outdated
Comment thread tests/FSharp.Data.GraphQL.Tests/ObjectListFilter/TypeCoercionValueTests.fs Outdated
- Moved filter operators and LINQ logic to ObjectListFilterModule.fs
- Added `TypeCoercion.fs` for automatic filter value coercion (`Guid`, `DateTime`, F# DUs, etc.)
- Introduced `FilterValueCoercer` and extended `ObjectListFilterLinqOptions` for custom coercion
- Centralized filter suffix constants in `FilterSuffixConstants.fs`
- Updated `SchemaDefinitions.fs` to use new suffix constants
- Added `vtryFind` and `vtryPick` utilities for arrays/lists in `Extensions.fs`
- Improved code style, documentation, and function signatures
Replaces custom value coercers with 'System.Text.Json'-based coercion in 'ObjectListFilter', supporting advanced scenarios like F# DUs and CLR enums via 'JsonSerializerOptions'. Updates 'ObjectListFilterLinqOptions' to accept 'JsonSerializerOptions'. Refactors 'TypeCoercion' module to use JSON serialization/deserialization for all type conversions. Updates filter application logic and expands the test suite with new files to cover a wide range of coercion scenarios. Updates documentation and usage examples accordingly.
* Added bug report for InputObject array type mismatch with analysis and test cases
* Added type coercion guide for ObjectListFilter with usage and API docs
* Introduced format-changed-files.ps1 to batch-format changed F# files via Fantomas
* Updated schema snapshots for relay-style connections and new scalars
* Refactored field_aliases.fsx for relay-style friends connection
* Optimized TypeCoercion.fs to use Utf8JsonWriter for value coercion
* Added prompt template for automated PR/issue description generation
Updated all string comparison operations in `ObjectListFilter` and filter parsing logic to use `StringComparer.CurrentCulture` or `StringComparer.CurrentCultureIgnoreCase` instead of `Ordinal`/`OrdinalIgnoreCase`. Adjusted related test expectations to match. This ensures string-based filters now respect the current culture's case rules.
@xperiandri xperiandri force-pushed the copilot/ObjectListFilter-file-coercion branch from c882576 to 2b531ac Compare July 9, 2026 14:02
@xperiandri xperiandri force-pushed the copilot/ObjectListFilter-file-coercion branch from e1fc28f to 01fb5ee Compare July 9, 2026 14:25
@xperiandri xperiandri requested a review from Copilot July 9, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces automatic coercion of ObjectListFilter primitive values to the target CLR property types (e.g., Guid, date/time types, enums, and F# DUs) during LINQ filter application, and adds a dedicated test suite to validate coercion behavior.

Changes:

  • Added TypeCoercion middleware helper to coerce ObjectListFilter values based on reflected entity property types (including option/voption unwrapping and enumerable element coercion).
  • Refactored/moved ObjectListFilter LINQ implementation into ObjectListFilterModule.fs and extended ObjectListFilterLinqOptions to carry JsonSerializerOptions.
  • Added comprehensive coercion unit/integration tests and test categorization traits for LINQ/ObjectListFilter.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/FSharp.Data.GraphQL.Tests/TestAttributes.fs Adds shared xUnit trait constants for categorizing tests.
tests/FSharp.Data.GraphQL.Tests/SelectLinqTests.fs Adds LINQ category trait to existing LINQ tests.
tests/FSharp.Data.GraphQL.Tests/ObjectListFilter/TypeCoercionValueTests.fs New unit tests for primitive/value coercion via STJ.
tests/FSharp.Data.GraphQL.Tests/ObjectListFilter/TypeCoercionTests.Common.fs New shared test types/data and helpers for coercion scenarios.
tests/FSharp.Data.GraphQL.Tests/ObjectListFilter/TypeCoercionFilterTests.fs New integration-style tests validating coercion through ObjectListFilter.ApplyTo.
tests/FSharp.Data.GraphQL.Tests/ObjectListFilter/ObjectListFilterLinqTests.fs Moves/renames module and adds traits for categorization.
tests/FSharp.Data.GraphQL.Tests/ObjectListFilter/ObjectListFilterLinqGenerateTests.fs Moves/renames module and adds traits for categorization.
tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj Updates compile includes for moved/new test files.
src/FSharp.Data.GraphQL.Shared/Helpers/Extensions.fs Adds Array/List.vtryFind and vtryPick helpers used by coercion.
src/FSharp.Data.GraphQL.Server.Middleware/TypeSystemExtensions.fs Removes unused opens (cleanup).
src/FSharp.Data.GraphQL.Server.Middleware/TypeCoercion.fs New module implementing filter/value coercion.
src/FSharp.Data.GraphQL.Server.Middleware/SchemaDefinitions.fs Minor doc tweak for ObjectListFilter description string.
src/FSharp.Data.GraphQL.Server.Middleware/ObjectListFilterModule.fs New module containing LINQ translation + ApplyTo extension with coercion.
src/FSharp.Data.GraphQL.Server.Middleware/ObjectListFilter.fs Extends LINQ options to include JSON options; removes embedded LINQ implementation.
src/FSharp.Data.GraphQL.Server.Middleware/FSharp.Data.GraphQL.Server.Middleware.fsproj Adds new middleware source files to compilation.

Comment thread src/FSharp.Data.GraphQL.Server.Middleware/ObjectListFilterModule.fs Outdated
Comment thread src/FSharp.Data.GraphQL.Server.Middleware/TypeCoercion.fs Outdated
Comment thread src/FSharp.Data.GraphQL.Server.Middleware/TypeCoercion.fs
Comment thread src/FSharp.Data.GraphQL.Server.Middleware/TypeCoercion.fs Outdated
Comment thread src/FSharp.Data.GraphQL.Server.Middleware/TypeCoercion.fs Outdated
Comment thread src/FSharp.Data.GraphQL.Server.Middleware/ObjectListFilterModule.fs Outdated
Comment thread src/FSharp.Data.GraphQL.Server.Middleware/ObjectListFilterModule.fs Outdated
Comment thread src/FSharp.Data.GraphQL.Server.Middleware/ObjectListFilterModule.fs Outdated
Comment thread src/FSharp.Data.GraphQL.Server.Middleware/ObjectListFilter.fs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.


let hasEqualityOperator (``type`` : Type) =
``type``.GetMethods (BindingFlags.Public ||| BindingFlags.Static)
|> Seq.exists (fun m -> m.Name = " op_Equality")
let enumerableQueryType = typedefof<EnumerableQuery<_>>

let apply (options : ObjectListFilterLinqOptions<'T, 'D>) (filter : ObjectListFilter) (query : IQueryable<'T>) =
let isEnumerableQuery = query.GetType().GetGenericTypeDefinition () = enumerableQueryType
Comment on lines +282 to +286
match getCollectionInstanceContainsMethod memberType with
| ValueNone ->
let enumerableContains = getEnumerableContainsMethod valueType
Expression.Call (enumerableContains, castedMember, Expression.Constant (normalizedValue))
| ValueSome instanceContainsMethod -> Expression.Call (castedMember, instanceContainsMethod, Expression.Constant (normalizedValue))
@xperiandri xperiandri merged commit ab3b961 into dev Jul 9, 2026
6 checks passed
@xperiandri xperiandri deleted the copilot/ObjectListFilter-file-coercion branch July 9, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants