Object literal default value on a custom scalar fails with NoSuchElementException

オープン
#982 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@nboisnea がすでに取り組んでいます。

2026年10月8日 から。

  • #983 @nboisnea による — オープン
  • #985 @reginaldalfret による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
graphql, java, kotlin
領域
backend

調査の方向性

Start with DataTypeGenerator.kt and GenerateKotlinCode.kt, in the default-value generators named in the issue; trace how ObjectValue is handled for scalar fields versus input types. Check the existing array-default generation and tests for Java and Kotlin, then add coverage for mapped and unmapped scalar defaults, including object literals nested in lists. Done means supported mapped cases generate the expected initializers and unsupported cases fail with the stated contextual message.

索引モデルが issue の本文から書いたものです。

説明

An input field whose type is a custom scalar cannot have an object literal as default value. This is valid GraphQL (graphql-java accepts it), and should work as long as the the scalar implementation's parseLiteral accepts ObjectValues, but generateJava fails with:

Execution failed for task ':generateJava'.
> Collection contains no element matching the predicate.

This happens for both Java and Kotlin, whether or not the scalar has a typeMapping and whatever it is mapped to. It also happens for object literals nested in a list default ([JSON] = [{}]).

Reproduction

Plugin version 8.7.0:

scalar JSON

type Query {
    search(filter: FilterInput): String
}

input FilterInput {
    metadata: JSON = {}
}
generateJava {
    packageName = 'com.example'
    typeMapping = ['JSON': 'java.util.Map<String, Object>']
}

Java:

Caused by: java.util.NoSuchElementException: Collection contains no element matching the predicate.
	at com.netflix.graphql.dgs.codegen.generators.java.InputTypeGenerator.defaultCodeBlock(DataTypeGenerator.kt:946)
	at com.netflix.graphql.dgs.codegen.generators.java.InputTypeGenerator.generateCode(DataTypeGenerator.kt:246)
	...

Kotlin (language = 'kotlin'):

Caused by: java.util.NoSuchElementException: Collection contains no element matching the predicate.
	at com.netflix.graphql.dgs.codegen.generators.shared.GenerateKotlinCodeKt.generateKotlinCode(GenerateKotlinCode.kt:155)
	at com.netflix.graphql.dgs.codegen.generators.kotlin.KotlinInputTypeGenerator.generate(KotlinDataTypeGenerator.kt:124)
	...
Cause

The ObjectValue branch of the default value generators (DataTypeGenerator.kt for Java, GenerateKotlinCode.kt for Kotlin) assumes the field type is an input type and looks up its definition with first { ... }. When the field type is a scalar, no input type matches.

Expected
  • When the scalar is explicitly mapped to a Map, generate a map initializer, the same way ArrayValue generates a list:
    • Java: new HashMap<>() for {}, and a populated map for object literals with fields
    • Kotlin: emptyMap() for {}, and mapOf("key" to value, ...) for object literals with fields
  • Otherwise, fail with an explicit message naming the input type and field, rather than NoSuchElementException.
主要言語
Kotlin
スター
220
フォーク
123
平均マージ
1日 6時間
マージ済み PR(30日)
23

環境構築

はじめの一歩

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

Netflix/dgs-codegen のほかの issue

Netflix/dgs-codegen の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

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

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