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 摘要。