Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#623 コメント 0 件 リアクション 0 件 担当者 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分
マージ済み PR(30日)
20

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fsprojects/FSharp.Data.GraphQL のほかの issue

fsprojects/FSharp.Data.GraphQL の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。