commonMain.com.apollographql.apollo3.api.Assertions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-api-jvm Show documentation
Show all versions of apollo-api-jvm Show documentation
Apollo GraphQL API classes
@file:JvmMultifileClass
@file:JvmName("Assertions")
package com.apollographql.apollo3.api
import com.apollographql.apollo3.api.json.JsonReader
import com.apollographql.apollo3.exception.DefaultApolloException
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
/**
* Helper function for the Java codegen
*/
fun checkFieldNotMissing(value: Any?, name: String) {
if (value == null) {
throw DefaultApolloException("Field '$name' is missing or null")
}
}
fun assertOneOf(vararg args: Optional<*>) {
val presentArgs = args.filterIsInstance>()
if (presentArgs.size != 1) {
throw IllegalArgumentException("@oneOf input must have one field set (got ${presentArgs.size})")
}
// Possible cases:
// - Optional (value can be null)
// - Optional> (value can be Absent or Present but not Present(null))
val presentArg = presentArgs.first()
if (presentArg.value == null || presentArg.value == Optional.Absent) {
throw IllegalArgumentException("The value set on @oneOf input field must be non-null")
}
}
/**
* Helper function for the Kotlin codegen
*/
fun missingField(jsonReader: JsonReader, name: String): Nothing {
throw DefaultApolloException("Field '$name' is missing or null at path ${jsonReader.getPath()}")
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy