Introspection emits JSON-serialized value as `defaultValue` instead of a GraphQL literal (breaks enum defaults)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 65/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- fsharp
- Ambito
- api
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- F#
- Stelle
- 407
- Fork
- 74
- Merge medio
- 15h 59m
- PR unite (30g)
- 20
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fsprojects/FSharp.Data.GraphQL
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
fsprojects/FSharp.Data.GraphQL#613 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
fsprojects/FSharp.Data.GraphQL#596 ·
I maintainer di solito rispondono entro 1 giorno
-
`documentId` has different values for the same query contentForse già presa @xperiandri l’ha presa 149 giorni fa. Aperta
fsprojects/FSharp.Data.GraphQL#573 · 1 reazione · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
-
FR: Suave packageForse già presa @xperiandri l’ha presa 149 giorni fa. Aperta
fsprojects/FSharp.Data.GraphQL#566 · 1 commento · 1 reazione · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
fsprojects/FSharp.Data.GraphQL#542 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di fsprojects/FSharp.Data.GraphQL
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
cmlarsen/writemorebetter#158 ·
I maintainer di solito rispondono entro 1 giorno
-
Notifications pagination accepts NaN and negative LIMIT/OFFSETForse già presa @Senthil455 l’ha presa oggi. ApertaBUGS MEDIUM
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
elixpo/blogs.elixpo#419 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: agent_final_response still returns the abandoned branch's answer after navigate moves HEAD backForse già presa @enyst l’ha presa oggi. Apertabug priority:low ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
OpenHands/software-agent-sdk#5822 ·
I maintainer di solito rispondono entro 1 giorno
-
area: server enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
scs0209/laya-guard#52 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno