Android Apollo 3 Migration Resources

Back with a few more migration questions. I’ve finally been able to get back to migration from 2 to 3 and have things building but there are quite a few things I wasn’t able to find any documentation on migration for and there are some things that appear to maybe not be working as intended. For reference I’m using beta03. The 2 things I’m looking to solve now at the moment are:

  • What is the replacement for useHttpGetMethodForQueries and useHttpGetMethodForPersistedQueries? I thought that maybe an HttpInterceptor was the right way to go to force Post as opposed to passing false for those 2 legacy methods but unfortunately that doesn’t appear to be working. The next thing I’ll look to do is set the ExecutionContext for the ApolloRequest as it seems like that should be able to dictate the method used. But I’m more just curious if there is something I’m missing here or if ExecutionContext is indeed the correct way to go about this now.

  • The other thing that has me is custom scalars. As per the the migration guide I’ve updated gradle to use customScalarsMapping but I get errors about my custom scalars not being mappable to the type I’ve set there. For reference we are migrating 2 different types to a String. I see in the v2 docs that maybe we should have been setting a CustomTypeAdapter but we never did so and things still worked. I’m assuming we just need to addCustomScalarAdapter now?

There are other things as well that I’m going to need to track down that I haven’t quite gotten to yet like batching so I think a bigger/better question to ask here to avoid coming back with more questions is if there is any resource for documentation/migration that I should be using. I have been referencing the docs and release notes but I feel like there is a bit of a gap in either documentation or knowledge on my end on how to find the correct resources. In fairness I’m far from an expert in this realm but any advice to help teach me how to fish would be very appreciated.

Thanks :smile:

1 Like

Hi :wave:Thanks for the detailed write up!

Regarding Auto Persisted Queries, you can control the HTTP method with parameters on ApolloClient.Builder.autoPersistedQueries(). The default is to send hashed queries using GET and fallback to POST when the full document needs to be sent:

fun ApolloClient.Builder.autoPersistedQueries(
    httpMethodForHashedQueries: HttpMethod = HttpMethod.Get,
    httpMethodForDocumentQueries: HttpMethod = HttpMethod.Post,
    hashByDefault: Boolean = true,
)

Regarding custom scalars, you are right that you need to explicitly call addCustomScalarAdapter(MyCustomScalar.type, StringAdapter). We can certainly add back the functionality to fallback to the builtin adapters although this has the slight inconvenient of doing an extra (failed) adapter lookup before falling back to the builtin adapter. So it might encourage less performant patterns. Maybe that’s overthinking it though and the ease of use of not having to register the adapter is worth the performance penalty. We’ll look into it!

In general, we’re hard at work on documentation at the moment so this is all precious feedback, thanks a lot :pray:. The docs you mentioned have a page for persisted queries as well as for query batching. I’d be curious to have your feedback about it if you see things we can add there? Or maybe organize differently?
Thanks again!

1 Like

Thanks so much for the response! I know this is very much WIP so I really appreciate it. I must have overlooked those bits in the docs or maybe they just weren’t there the last time I looked and I completely missed them circling back so my bad there for sure. Will definitely keep a better eye on incoming changes and try to do a better job of exploring :sweat_smile:

As far as scalars mapping goes, it’s definitely good to know we have to do this now for builtin adapters I think it would be worthwhile to point out in the migration guide where custom scalars are mentioned. That said I don’t mind that we have to be explicit about it. It does make things a little difficult in my case because of some code organization decisions made long ago mean the type isn’t available where we need it right now but that’s a me issue :smiley:

I think organizationally the docs are fine enough but I did find some of the migration documentation most useful in terms of API.A has a new equivalent of API.B. I know that can also be quite overwhelming to provide an exhaustive list for though. I’ve also been using the search to find old API docs but in the case of useHttpGetMethodForQueries I didn’t see anything in the v2 docs. I think I probably need to start looking at the codebase for v2 to help guide me as well to make sure I know what the APIs apply to. That should help point me in the right direction I think. Anyway, that’s just me rambling but maybe it’ll be useful for someone else.

Unfortunately for me I’m taking on quite a large migration with years of changes and fuzzy knowledge so trying to wrangle some of these things has been overwhelming paired with also trying to understand all of the things we’re doing today in v2. Still I very much appreciate the help I’ve gotten here. Thanks so much!

Hi :wave:. As a follow up, next beta will have:

We’re still ironing out the docs so any question you have, feel free to ask, this is precious feedbacks to improve them!