Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

"Object must implement IConvertible" when using built-in ID

Đang mở
#306 4 bình luận 1 reaction 2 người được giao Xem trên GitHub

@xperiandri đang làm issue này rồi.

Từ ngày 17/5/2026.

  • #572 của @copilot-swe-agent — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

Description

When using built-in ID GraphQL type to represent the Guid .NET type I'm getting Object must implement IConvertible error back from the executor.

Repro steps
open FSharp.Data.GraphQL
open FSharp.Data.GraphQL.Types

type Person =
    { Id: System.Guid
      Name: string }

let people: List<Person> = [ 
    { Id = System.Guid.Parse("d6c684d9-aaaa-4e88-bbb2-0bb584f1661d"); Name = "Person A" }
    { Id = System.Guid.Parse("d6c684d9-bbbb-4e88-bbb2-0bb584f1661d"); Name = "Person B" } ]

let ProjectType: ObjectDef<Person> = Define.Object(
    name = "Person",
    fields = [
        Define.AutoField("id", ID)
        Define.AutoField("name", String)
    ])

let QueryRoot = Define.Object("Query", [
    Define.Field("people", ListOf ProjectType, fun ctx () -> 
        printfn "Querying for people"
        people
    )
])

let schema = Schema(query = QueryRoot)

let executor = Executor(schema = schema)

let query = "{people{id}}"
let result = executor.AsyncExecute(query) |> Async.RunSynchronously
printfn "%A" result
Expected behavior

I'm getting a list of people IDs back.

Actual behavior

I'm receiving the following error:

System.InvalidCastException: Object must implement IConvertible.\r\n   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)\r\n   at System.Convert.ChangeType(Object value, Type conversionType)\r\n   at FSharp.Data.GraphQL.Types.SchemaDefinitions.coerceIDValue[t](Object x)\r\n   at FSharp.Data.GraphQL.Types.SchemaDefinitions.ID@2581-1.Invoke(Object x)\r\n   at FSharp.Data.GraphQL.Types.ScalarDefinition`1.FSharp-Data-GraphQL-Types-ScalarDef-CoerceValue(Object value)\r\n   at FSharp.Data.GraphQL.Execution.direct(OutputDef returnDef, ResolveFieldContext ctx, FSharpList`1 path, Object parent, Object value)\r\n   at FSharp.Data.GraphQL.Execution.executeObjectFields(FSharpList`1 fields, String objName, ObjectDef objDef, ResolveFieldContext ctx, FSharpList`1 path, Object value)\r\n   at Microsoft.FSharp.Collections.ArrayModule.MapIndexed[T,TResult](FSharpFunc`2 mapping, T[] array) in F:\\workspace\\_work\\1\\s\\src\\fsharp\\FSharp.Core\\array.fs:line 349\r\n   at FSharp.Data.GraphQL.Execution.direct$cont@329-1(ResolveFieldContext ctx, FSharpList`1 path, Object value, String name, OutputDef innerDef, Unit unitVar)\r\n   at FSharp.Data.GraphQL.Execution.direct$cont@312(OutputDef returnDef, ResolveFieldContext ctx, FSharpList`1 path, Object parent, Object value, String name, Unit unitVar)\r\n   at FSharp.Data.GraphQL.Execution.executeRootOperation@563(ExecutionContext ctx, ObjectDef objdef, Object rootValue, String tupledArg0, ExecutionInfo tupledArg1)\r\n   at FSharp.Data.GraphQL.Execution.executeQueryOrMutation(Tuple`2[] resultSet, ExecutionContext ctx, ObjectDef objdef, Object rootValue)\r\n   at <StartupCode$FSharp-Data-GraphQL-Server>.$Executor.clo@110-4.Invoke(Unit unitVar)\r\n   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in F:\\workspace\\_work\\1\\s\\src\\fsharp\\FSharp.Core\\async.fs:line 398\r\n   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in F:\\workspace\\_work\\1\\s\\src\\fsharp\\FSharp.Core\\async.fs:line 109
Known workarounds

You can change the Type definition of the Guid field to be just a String, but semantically that's not correct (I'm still getting my head around GraphQL, but as far as I know that's the whole purpose of using ID type - it is not intended to be human‐readable):

let ProjectType: ObjectDef<Person> = Define.Object(
    name = "Person",
    fields = [
        Define.AutoField("id", String)
        Define.AutoField("name", String)
    ])
Ngôn ngữ chính
F#
Star
406
Fork
74
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
14

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của fsprojects/FSharp.Data.GraphQL

Tất cả issue của fsprojects/FSharp.Data.GraphQL

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.