Introspection emits JSON-serialized value as `defaultValue` instead of a GraphQL literal (breaks enum defaults)
维护者通常 1 天内回复
评估
- 难度
- 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 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.
- 主要语言
- F#
- 星标
- 407
- 派生
- 74
- 平均合并
- 15 小时 59 分钟
- 30 天内合并 PR
- 20
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fsprojects/FSharp.Data.GraphQL 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 52/100
fsprojects/FSharp.Data.GraphQL#613 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 45/100
fsprojects/FSharp.Data.GraphQL#596 ·
维护者通常 1 天内回复
-
`documentId` has different values for the same query content可能已有人在做 @xperiandri 于 149 天前认领。 未关闭
fsprojects/FSharp.Data.GraphQL#573 · 1 个 reaction · 已指派 2 人 ·
维护者通常 1 天内回复
-
FR: Suave package可能已有人在做 @xperiandri 于 149 天前认领。 未关闭
fsprojects/FSharp.Data.GraphQL#566 · 1 条评论 · 1 个 reaction · 已指派 2 人 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 30/100
fsprojects/FSharp.Data.GraphQL#542 ·
维护者通常 1 天内回复
查看 fsprojects/FSharp.Data.GraphQL 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 条评论 ·
维护者通常 3 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 85/100
FujiNetWIFI/fujinet-lib#122 · 1 条评论 ·
维护者通常 1 天内回复
-
effort: low prio: low ready
难度 2/5 1-3 小时 新手友好度 82/100
digitalfabrik/integreat-cms#4616 ·
维护者通常 5 天内回复
-
[BUG] Cloudflare KV binding 模式下 kvDriver.list() 沿用 EdgeOne 语义,字段名不匹配导致 key 格式下初始化 500 并耗尽 list 配额可能已有人在做 @wumingzhinu 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 64/100
OpenListTeam/OpenList-Worker#125 ·
维护者通常 2 天内回复
-
refactor topic-map
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复