Introspection emits JSON-serialized value as `defaultValue` instead of a GraphQL literal (breaks enum defaults)
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 65/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- fsharp
- Área
- api
Línea de trabajo
Start in src/FSharp.Data.GraphQL.Server/Schema.fs at the __InputValue.defaultValue construction, then trace the input type definitions used for introspection. Reproduce the DesiredAttendanceMode example and verify that defaultValue is emitted as LOCAL and that enum, input-object, scalar, list, nullable, and null defaults are valid GraphQL literals.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Problem
__InputValue.defaultValue is produced with System.Text.Json instead of being printed as a GraphQL value literal:
// src/FSharp.Data.GraphQL.Server/Schema.fs
let defaultValue =
inputDef.DefaultValue
|> ValueOption.map (fun value -> JsonSerializer.Serialize(unwrap value, schemaConfig.JsonOptions))
Per the spec, defaultValue is "A GraphQL-formatted string representing the default value for this input value" (spec §4.2.3 __InputValue). JSON output is only coincidentally valid for numbers, booleans, simple strings and null. It is invalid for:
- enums: the GraphQL enum value name (from
Define.EnumValue) is never used; the CLR value is serialized instead; - input objects: JSON quotes the keys (
{"a":1}), while GraphQL literals do not ({a: 1}); - custom scalars: the scalar's output coercion is bypassed.
Clients that build a schema from introspection (graphql-js buildClientSchema, used by graphql-codegen, nitro-graphql, etc.) parse every defaultValue with parseValue and fail.
Repro
[<RequireQualifiedAccess>]
type DesiredAttendanceMode =
| Local
| Remote
let DesiredAttendanceModeType =
Define.Enum<DesiredAttendanceMode> (
"DesiredAttendanceMode",
[
Define.EnumValue ("LOCAL", DesiredAttendanceMode.Local)
Define.EnumValue ("REMOTE", DesiredAttendanceMode.Remote)
]
)
type InputAttendee = { UserId : string; AttendanceMode : DesiredAttendanceMode }
let InputAttendeeType =
Define.InputObject<InputAttendee> (
"InputAttendee",
[
Define.Input ("userId", StringType)
Define.Input ("attendanceMode", DesiredAttendanceModeType, defaultValue = DesiredAttendanceMode.Local)
]
)
Actual introspection (with FSharp.SystemTextJson union encoding in JsonOptions)
{
"name": "attendanceMode",
"type": { "kind": "ENUM", "name": "DesiredAttendanceMode", "ofType": null },
"defaultValue": "{\"Case\":\"Local\"}"
}
Even with default STJ options the result would be "\"Local\"" or "0", both invalid for an enum.
Expected
"defaultValue": "LOCAL"
Client error (graphql-js buildClientSchema)
Syntax Error: Expected Name, found String "Case".
Suggested fix
Print the default value using the input type definition (analogous to graphql-js astFromValue + print):
EnumDef→ find theEnumValuewhoseValueequals the default and emit itsName(unquoted);ScalarDef→ apply the scalar output coercion, then print as a GraphQL literal (strings quoted/escaped);ListOf→[v1, v2]recursively;InputObjectDef→{field: value}recursively, using field names from the definition;Nullable/null→null.
Workaround
Make the input nullable, drop defaultValue, and apply the default in resolver code.
- Lenguaje dominante
- F#
- Estrellas
- 407
- Forks
- 74
- Merge medio
- 15 h 59 min
- PR fusionados (30 d)
- 20
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de fsprojects/FSharp.Data.GraphQL
-
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
fsprojects/FSharp.Data.GraphQL#613 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
fsprojects/FSharp.Data.GraphQL#596 ·
Los mantenedores suelen responder en 1 día
-
`documentId` has different values for the same query contentPosiblemente ocupada @xperiandri la tomó hace 150 días. Abierto
fsprojects/FSharp.Data.GraphQL#573 · 1 reacción · 2 asignados ·
Los mantenedores suelen responder en 1 día
-
FR: Suave packagePosiblemente ocupada @xperiandri la tomó hace 151 días. Abierto
fsprojects/FSharp.Data.GraphQL#566 · 1 comentario · 1 reacción · 2 asignados ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
fsprojects/FSharp.Data.GraphQL#542 ·
Los mantenedores suelen responder en 1 día
Todos los issues de fsprojects/FSharp.Data.GraphQL
Issues similares
-
[BUG]: Prompt compressor crashes with TypeError when a past chat has a non-string response.textPosiblemente ocupada @ManojDevarajulu la tomó hoy. Abiertopossible bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Mintplex-Labs/anything-llm#6737 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Medio día Aptitud para principiantes 62/100
ibm-granite/granite.build#504 ·
Los mantenedores suelen responder en 2 días
-
area/plugin good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
kestra-io/plugin-kestra#200 ·
Los mantenedores suelen responder en 1 día
-
`LazyFrameRemote` and `ExecuteRemote` sinks do not accept `Path`, like `LazyFrame` sinks do.Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
api-platform/core#8690 ·
Los mantenedores suelen responder en 1 día