Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#623 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@xperiandri đang làm issue này rồi.

Từ ngày 3/10/2026.

  • #625 của @xperiandri — đang mở

Đá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 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.

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của fsprojects/FSharp.Data.GraphQL

Tất cả issue của fsprojects/FSharp.Data.GraphQL

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.