Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉
#623 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@xperiandri 已經在處理了。

開始於 2026年10月3日。

  • #625 來自 @xperiandri —— 未關閉

評估

難度
4/5
預估耗時
3-5 天
新手友好度
65/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
fsharp
領域
api

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
F#
星號
407
分支
74
平均合併
15 小時 59 分鐘
30 天內合併 PR
20

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

fsprojects/FSharp.Data.GraphQL 的其他 Issue

查看 fsprojects/FSharp.Data.GraphQL 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。