Add tests for ID scalar coercion with Guid and int64 values#572
Add tests for ID scalar coercion with Guid and int64 values#572Copilot wants to merge 5 commits into
Conversation
bb9dd5b to
0171893
Compare
…ory` and remove external server orchestration from build (#564) Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Andrii Chebukin <XperiAndri@Outlook.com>
…compile time (#569) Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Andrii Chebukin <XperiAndri@Outlook.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/d2fe5523-e81b-4d08-813e-b7f106345347 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/d2fe5523-e81b-4d08-813e-b7f106345347 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
0171893 to
99ffff5
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds regression coverage for ID scalar output coercion when .NET values include Guid, especially around GraphQL IDType serialization.
Changes:
- Adds direct
IDType.CoerceOutputtests for string, int, int64, and Guid values. - Adds execution tests for a
Personobject with a Guid-backed ID field through AutoField and explicit Field definitions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
tests/FSharp.Data.GraphQL.Tests/Variables and Inputs/CoercionTests.fs |
Adds scalar output coercion coverage for IDType. |
tests/FSharp.Data.GraphQL.Tests/ExecutionTests.fs |
Adds end-to-end execution tests for Guid-backed ID fields. |
| let PersonType = | ||
| Define.Object<PersonWithGuidId>( | ||
| "Person", | ||
| [ Define.Field("id", IDType, fun _ (p : PersonWithGuidId) -> string p.Id) |
There was a problem hiding this comment.
Yes, the reviewer was correct. Because IDType : ScalarDefinition<string>, the F# type system constrains any explicit Define.Field(..., IDType, ...) resolver to return string — so coerceIdValue only ever saw a boxed string, never a Guid.
Fixed in 3a79315: replaced that test with Execution handles ID scalar: serializes int64 field via AutoField, which uses AutoField on a PersonWithInt64Id.Id : int64 field. The auto-generated resolver returns a boxed int64, exercising the | _ -> Some(string x) fallback branch in coerceIdValue with a different non-IConvertible-reliant type.
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/665410b5-82a2-4766-8ae5-0fd2f16a121e Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
Using
IDType(GraphQL built-inScalarDefinition<string>) with aSystem.Guid.NET field previously threw"Object must implement IConvertible"because the oldcoerceIDValue<t>usedConvert.ChangeType, which requiresIConvertible.The fix was already present in
coerceIdValuevia the| _ -> Some(string x)fallback (callingToString()on any value). This PR adds test coverage to lock in that behaviour.Changes
ExecutionTests.fs: Two end-to-end execution tests exercisingcoerceIdValuewith non-string values through theAutoFieldpath:Guid-backed ID field — the exact scenario from the original issueint64-backed ID field — exercises the same| _ -> Some(string x)fallback branch with a different non-IConvertibletypeCoercionTests.fs: DirectCoerceOutputunit tests verifyingIDTypeserializesstring,int,int64, andGuidvalues to their expected string representations.