https://kotlinlang.org logo
Title
o

Oleksii Yerastov

12/09/2020, 8:55 AM
Hi there! Can somebody tell me what can cause an issue when I receive unknown
enum
value from API and leads to error response? As I can see apollo generates
safeValueOf(rawValue: String)
method in enum class alongside with
/**
 * Auto generated constant for unknown enum values
 */
UNKNOWN__("UNKNOWN__");
value for unknown enums. Also there is usage of this method in
operator fun invoke(reader: ResponseReader)
for entity that contains this enum. Do I need to explicitly enable something to make this work so I apollo can parse unknown enum values to UNKNOWN?
m

mbonnin

12/09/2020, 8:57 AM
Hi ! What error are you getting? I think unknown enum values should be map to
UNKNOWN
automatically
You can look into
sealedClassesForEnumMatching
if you want to read the rawValue of unknown enums
o

Oleksii Yerastov

12/09/2020, 9:01 AM
I just receive
Can't serialize value (/me/roles[2]) : Invalid input for Enum 'MyEnum'. Unknown value 'NEW_ENUM_VALUE'
in
response.response.errors
where
response
is
ApolloResponse
accessed in ApolloRequestInterceptor
so it is not mapping to
UNKNOWN
and just fails during mapping of response
m

mbonnin

12/09/2020, 9:08 AM
It sounds like this happens while serializing arguments ?
Mmm or maybe your server doesn't like NEW_ENUM_VALUE
Yep, more likely a server error
o

Oleksii Yerastov

12/09/2020, 9:10 AM
It happens during parsing of response from server
I receive array of enums with unknown value to client
client 100% is not sending this enum value to server
👍 1
m

mbonnin

12/09/2020, 9:11 AM
I would expect a ApolloParseException for client parsing errors, response.errors should come from the server
Can you hook a proxy or httplogginginterceptor to rule that option out?
o

Oleksii Yerastov

12/09/2020, 9:16 AM
it’s happening in multiplatform code so there is no httplogginginterceptor and I’ll need your guidance for further investigation)
m

mbonnin

12/09/2020, 9:18 AM
I see. I'll be at my computer in ~20min, will dig more then
o

Oleksii Yerastov

12/09/2020, 9:19 AM
thanks, will be waiting🙏
m

mbonnin

12/09/2020, 9:46 AM
Is there any chance you can share your query?
To debug this further, a proxy would be quite useful, this really looks like this error is coming from the server. If a proxy is not an option, you can customize the default HttpNetworkTransport by using expect/actual. Something like:
actual fun customApolloHttpNetworkTransport(
    serverUrl: String, 
): NetworkTransport =  ApolloHttpNetworkTransport(
    serverUrl = serverUrl,
    headers = emptyMap(),
    httpCallFactory = OkHttpClient.Builder().addInterceptor(HttpLoggingInterceptor().apply{
      level = Level.BODY
    }).build(),
    httpMethod = <http://HttpMethod.Post|HttpMethod.Post>    
)
o

Oleksii Yerastov

12/09/2020, 9:56 AM
Oh, we found the reason and it is actually some internal code on backend😣 So sorry for bothering you without checking appropriately
m

mbonnin

12/09/2020, 9:56 AM
Cool 👍
Glad that you found the error, don't hesitate to share any feedback
o

Oleksii Yerastov

12/09/2020, 9:57 AM
thanks!❤️
👍 1