GraphQLError(Variable 'a' has coerced Null value for NonNull type)
GraphQLError(message=Variable 'variable' has coerced Null value for NonNull type)가 나타났을 때 대체적으로 다음과 같은 두 가지 모델이 있었다.질의 측면의 매개변수 선언이 비어 있음
Skima 선언에서 파라미터가 non-null
UserInput!인 경우extend type Mutation {
  createUser(input: UserInput!) : User!
}
input UserInput {
  name: string
}
UserInput를 조회할 때 오류가 발생했습니다.mutation CreateUser($input: UserInput) { // <- nullableで宣言してしまっている。
    createUser(input: $input) {
        id
    }
}
UserInput!에서 선언하면 OK.해당 매개 변수가 전달되지 않았습니다.
Spring-Boot에서 GraphiQl에 대한 요청은 다음과 같습니다.
import kotlinx.coroutines.withContext
import org.springframework.http.HttpEntity
import org.springframework.http.HttpMethod
import org.springframework.web.client.RestOperations
import org.springframework.web.client.exchange
import kotlin.coroutines.coroutineContext
data class GraphQlQuery(val query: String, val variables: Map<String, Any>?)
suspend fun post(url: String, restOperations: RestOperations, query: GraphQlQuery): String {
    return withContext(coroutineContext) {
        val response = restOperations
            .exchange<String>(url, HttpMethod.POST, HttpEntity(query))
        requireNotNull(response.body)
    }
}
post("https://...", restOperations, 
  GraphQlQuery("""
    mutation CreateUser($input: UserInput!) {
    createUser(input: $input) {
        id
    }
  }
  """,
  mapOf("name" to "mike") // おや?
)
input UserInput {
  name: string
}
data class UserInput(val name: String)
post("https://...", restOperations, 
  GraphQlQuery("""
    mutation CreateUser($input: UserInput!) {
    createUser(input: $input) {
        id
    }
  }
  """,
  mapOf("input" to UserInput("mike")) // Yes!
)
Reference
이 문제에 관하여(GraphQLError(Variable 'a' has coerced Null value for NonNull type)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/sys1yagi/articles/5fafc8ba948ee7텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)