Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#306 4 comentarios 1 reacción 2 asignados Ver en GitHub

@xperiandri ya está trabajando en esto.

Desde el 17/5/2026.

  • #572 de @copilot-swe-agent — abierto

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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)
    ])
Lenguaje dominante
F#
Estrellas
406
Forks
74
Merge medio
1 d 8 h
PR fusionados (30 d)
14

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de fsprojects/FSharp.Data.GraphQL

Todos los issues de fsprojects/FSharp.Data.GraphQL

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.