Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Introspection emits JSON-serialized value as `defaultValue` instead of a GraphQL literal (breaks enum defaults)

Aperta
#623 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@xperiandri ci sta già lavorando.

Dal 3/10/2026.

  • #625 di @xperiandri — aperta

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 the EnumValue whose Value equals the default and emit its Name (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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fsprojects/FSharp.Data.GraphQL

Tutte le issue di fsprojects/FSharp.Data.GraphQL

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.