Hi there! Can somebody tell me what can cause an i...
# apollo-kotlin
o
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
Copy code
/**
 * 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
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
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
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
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
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
it’s happening in multiplatform code so there is no httplogginginterceptor and I’ll need your guidance for further investigation)
m
I see. I'll be at my computer in ~20min, will dig more then
o
thanks, will be waiting🙏
m
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:
Copy code
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
Oh, we found the reason and it is actually some internal code on backend😣 So sorry for bothering you without checking appropriately
m
Cool 👍
Glad that you found the error, don't hesitate to share any feedback
o
thanks!❤️
👍 1
146 Views