Closed15
Variable 'Id' has coerced Null value for NonNull type 'String!'

val query = GetSamplePostQuery
.builder()
.id("xxxxxxxx")
.timestampMs(999999)
.build()
こんな感じで書いたら
Variable 'Id' has coerced Null value for NonNull type 'String!'
これで怒られた

環境はこれで 使ってるのはこれ

aws appsync の方から直接叩いてみて取得できるかみる

ここで試してみる

0からリソース作っていく

普通にできてしまった
どうして

type UpperCamelCaseLog @model @key(fields: ["Kind", "TimestampMs"]) {
Id: ID!
Kind: String!
TimestampMs: Float!
Content: String!
}
これを作って build すると、すごい怒られる
なぜか id が2回定義されている
field に id がなかったら id を作成する、みたいな挙動でもしてるのかな

作ったモデルはこれ

なぜか id が2回定義されている
field に id がなかったら id を作成する、みたいな挙動でもしてるのかな
これであってそう
Id
のフィールドを消しても id
が作られた
CreateUpperCamelCaseLogInput(Input<String> id, @Nonnull String kind, double timestampMs,
@Nonnull String content) {
this.id = id;
this.kind = kind;
this.timestampMs = timestampMs;
this.content = content;
}

定義はこれ

Id
のフィールド消して再チャレンジ
private suspend fun get(kind: String, timestampMs: Double) : GetUpperCamelCaseLogQuery.GetUpperCamelCaseLog? {
val query = GetUpperCamelCaseLogQuery
.builder()
.kind(kind)
.timestampMs(timestampMs)
.build()
return suspendCoroutine { continuation ->
client.query(query).responseFetcher(NETWORK_FIRST).enqueue(object :
GraphQLCall.Callback<GetUpperCamelCaseLogQuery.Data>() {
override fun onFailure(e: ApolloException) {
throw e
}
override fun onResponse(response: Response<GetUpperCamelCaseLogQuery.Data>) {
if (response.errors().size > 0) {
continuation.resumeWithException(Exception(response.errors().toString()))
return
}
val result = response.data()!!.upperCamelCaseLog
continuation.resume(result)
}
})
}
}
いつか見たエラー
java.lang.Exception: [Error{message='Variable 'Kind' has coerced Null value for NonNull type 'String!'', locations=[Location{line=1, column=28}], customAttributes={}}]
やっぱり UpperCamel のときにバグるっぽい

Issue だすかな…

Issue だすかな…

これは動く
これは動かない
差は field name が UpperCamel か lowerCamel かだけ
(id のこともあるけどここでは無視して良いはず)

get をそのまま使うやつだけ落ちる
list の中で get と同じ条件で filter してあげると通る
このスクラップは2021/04/16にクローズされました