Introspection emits JSON-serialized value as `defaultValue` instead of a GraphQL literal (breaks enum defaults)
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 65/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- fsharp
- Lĩnh vực
- api
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- F#
- Star
- 407
- Fork
- 74
- Merge trung bình
- 15 giờ 59 phút
- Pull request đã merge (30 ngày)
- 20
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của fsprojects/FSharp.Data.GraphQL
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
fsprojects/FSharp.Data.GraphQL#613 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
fsprojects/FSharp.Data.GraphQL#596 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`documentId` has different values for the same query contentCó thể đã có người làm @xperiandri đã nhận 149 ngày trước. Đang mở
fsprojects/FSharp.Data.GraphQL#573 · 1 reaction · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
FR: Suave packageCó thể đã có người làm @xperiandri đã nhận 149 ngày trước. Đang mở
fsprojects/FSharp.Data.GraphQL#566 · 1 bình luận · 1 reaction · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
fsprojects/FSharp.Data.GraphQL#542 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của fsprojects/FSharp.Data.GraphQL
Issue tương tự
-
[Bug]: LangGraph Store sync put bypasses namespace validationCó thể đã có người làm @ktz03 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
volcengine/OpenViking#6050 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Streamed /v1/chat/completions sends unredacted agent error text (keys) in the final chunkCó thể đã có người làm @rodricksz4h5 đã nhận hôm nay. Đang mởarea/streaming comp/gateway P2 type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NousResearch/hermes-agent#138245 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
🐞 bug pending triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
CircuitVerse/CircuitVerse#8025 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 1 ngày