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分
- マージ済み PR(30日)
- 20
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 件 · 担当者 2 名 ·
メンテナーはふだん 1 日以内に返信
-
FR: Suave package対応中かも @xperiandri が 150 日前に担当しました。 オープン
fsprojects/FSharp.Data.GraphQL#566 · コメント 1 件 · リアクション 1 件 · 担当者 2 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
fsprojects/FSharp.Data.GraphQL#542 ·
メンテナーはふだん 1 日以内に返信
fsprojects/FSharp.Data.GraphQL の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
onyx-dot-app/onyx#16016 ·
メンテナーはふだん 1 日以内に返信
-
reproduced
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
anomalyco/opencode#55369 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
feature
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
manyfold3d/manyfold#7346 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
chaitin/agent-compose#770 ·
メンテナーはふだん 1 日以内に返信