Stylianos Gakis
07/27/2023, 10:37 PMorg.json.JSONObject
which comes from Android, and one for a class coming from the Adyen Android SDK which I don’t think ever would not be an Android library.Stylianos Gakis
07/27/2023, 10:40 PMmapScalarToKotlinString
on them, and then use the adapter manually whenever there is a place that does in fact want to use that model. And that module can be Android, that’s fine.
Provided my idea makes sense and would work in the first place of course 😄Stylianos Gakis
07/27/2023, 11:18 PM// Replace
dependencies {
// ...
// Get the generated schema types (and fragments) from the upstream schema module
apolloMetadata(project(":schema"))
// You also need to declare the schema module as a regular dependency
implementation(project(":schema"))
}
// With
dependencies {
// ...
// You still need to declare the schema module as a regular dependency
implementation(project(":schema"))
}
apollo {
service("service") {
// ...
// Get the generated schema types (and fragments) from the upstream schema module
dependsOn(project(":schema"))
}
}
```
But this shouldn’t change what I am trying to do I think.bod
07/28/2023, 7:31 AMwondering if I can turn my apollo schema module into a JVM oneCorrect, Apollo doesn't depend on Android, so it's perfectly OK for this to be a Java (without Android) module ...but it's also true that if you want the generated code to reference types that come from libraries that do depend on Android, then this will probably not work (although to be honest I'm not 100% certain! Can Java module never depend on Android modules? May be worth a try (as I'm typing this I think this shouldn't work as Java-only Gradle wouldn't know anything about
.aar
files for instance).
If that's the case, yes mapping to Strings may be a solution. Or depending on the scalar, not mapping at all, in which case this will result in them being generated as Any
and will effectively reflect the Json at runtime (so Map<String, Any>
for objects, etc.)bod
07/28/2023, 7:33 AMStylianos Gakis
07/28/2023, 7:48 AMAnyAdapter
to turn it into Any and then passing it through the serializer that the SDK is providing.
If I did not do this on this layer, I wouldn’t have access to the CustomScalarAdapters
, (which I suppose aren’t used here anyway, only if I had nested types in there which also require custom adapters), so I can just omit passing it through this adapter at all.
Would I then on the Android module need to do this thing again and pass it through AnyAdapter before being able to deserialize it?
My guess would be yes, otherwise the Any
given from the scalar itself would still inside there have stuff like __typename
right? Or instead of passing it through AnyAdapter to get the content out of it, maybe mapToKotlinString would do that for me in the first place?wasyl
07/28/2023, 7:52 AMAdyen
library you're mapping to? I'm asking because it's interesting that the backend returns fields that are considered so library-specific that they're mapped directly to those typeswasyl
07/28/2023, 7:54 AMapi
module though, so there's some duplication (but at the same time this allows us to do minor modifications to queries without those changes propagating through the entire app, so it's worth it)Stylianos Gakis
07/28/2023, 7:54 AMbod
07/28/2023, 7:55 AMThat's right, this isn't used at all for scalars, it can be ignored., (which I suppose aren’t used here anyway,CustomScalarAdapters
wasyl
07/28/2023, 7:56 AMStylianos Gakis
07/28/2023, 7:58 AMbod
07/28/2023, 8:00 AMAny
and then you can reuse your logic starting with return if (data is Map<*, *>)
, etc.Stylianos Gakis
07/28/2023, 8:02 AMapolloMetadata(…)
? I just wonder which other modules do you have that depend on generated-models? Having a bit hard time understanding how you don’t expose the generated models to any(?) other module aside your API? How do your repositories for example make a query if they don’t see the generated FooQuery() class?Stylianos Gakis
07/28/2023, 8:03 AMon your specific example that you linked, you could simply not map the scalar, so it would beRight, but I start this if check only after having passing it through the AnyAdapter, would I not still have to do this in some way? Theand then you can reuse your logic starting withAny
, etc.return if (data is Map<*, *>)
Any
that I receive if I don’t do anything, not even put mapScalarToKotlinString
on the scalar, wouldn’t it not be on the same shape as I have it after passing it through the AnyAdapter?bod
07/28/2023, 8:04 AMwouldn’t it not be on the same shape as I have it after passing it through the AnyAdapter?no that would be equivalent 🙂 The codegen actually will use AnyAdpater under the hood in that case
bod
07/28/2023, 8:04 AMStylianos Gakis
07/28/2023, 8:05 AMmapScalarToKotlinString
so that I get it on the exact same shape as I would in here. That’s really good to know, thank you!wasyl
07/28/2023, 8:05 AMgenerated-models
only contains Apollo's generated classes, queries and responses. api
module contains our own types that map ~1:1 to generated models, but with our own types. So for example generated-models
will have Apollo's generated SomeQuery
and SomeQueryData
and our api
will have object SomeQuery : ApiQuery<ApiResponseModel>
and data class ApiResponseModel
, where ApiQuery
is our abstraction over a query.
Then in apollo
we have an implementation that accepts ApiQuery
, uses mappings provided by adapter
module to transform them to Apollo classes, use Apollo classes to run the query, get the response, and again mappings from adapter
would map to our own types for responsesbod
07/28/2023, 8:06 AMmapScalarToKotlinString
and the server returns something that is not a String, like a Json object, it will fail)wasyl
07/28/2023, 8:06 AMapi
, so our own classes (there's also Api
class there with functions like query(ApiQuery<T>): Flow<T>)
. Rest is wired up in app DIStylianos Gakis
07/28/2023, 8:11 AMbod
07/28/2023, 8:16 AMwasyl
07/28/2023, 8:19 AMwasyl
07/28/2023, 8:21 AMtrue isolation vs convenience/verbositythat's a good summary — we just value isolation much more. IMO the benefits kick in when you have more libraries like that and you were consistent with the isolation everywhere. If it's only Apollo that would not be isolated then it's not that bad, but I think all libraries should be treated equally 😛
bod
07/28/2023, 8:27 AMStylianos Gakis
07/28/2023, 8:31 AMbod
07/28/2023, 8:32 AM