https://kotlinlang.org logo
Title
s

Samuel Michael

04/06/2021, 2:31 AM
Hey working with Android client and trying to figure out if we are able to import graphql fragments into multiple queries? I saw in the docs somewhere that webpack allows you to do something like
#import "./MyFragment"
that but so far no example in an Android context. Currently we are redefining the same huge fragments in multiple queries and would like to be able to extract all those into several separate fragment files and DRY up the main queries
w

wasyl

04/06/2021, 6:07 AM
We don’t import anything, and simply reuse fragments from different files (in the same directory)
s

Samuel Michael

04/07/2021, 6:37 AM
Hmm, that doesn't seem to work in our codebase, maybe we are using a different gradle process to generate the graphql classes, and it is not accounting for fragment dependencies, wonder how to troubleshoot/fix
w

wasyl

04/07/2021, 6:53 AM
Can you share more details how your setup looks? We have pretty straightforward apollo plugin configuration in a module, and
*.graphql
files under
src/main/grapqhl/com/package/…./queries
. In those
*.graphql
files some define fragments and some queries, and we can use all fragments from all queries no problem. I’m not sure what you mean by different gradle process. Do you have fragments and queries in different modules?
👍 1
s

Samuel Michael

04/08/2021, 11:45 AM
Thanks for the detailed response, yeah it turns out although we have already added apollo library we are using a homemade codegen gradle plugin. I put up a PR to add import functionality, maybe just move on to Apollo in near future since it seems to be working good based on your description.
w

wasyl

04/08/2021, 11:51 AM
We’ve been using Apollo plugin from the start, and started generating Kotlin code as soon as it became available. Other than occasional small hiccups that were promptly fixed everything’s been working very well for us 🙂 Out of curiosity, you’re using your own gradle plugin for codegen and generate exactly the code that apollo-android runtime expects? Or you’re just wrapping apollo codegen code in your own gradle plugin?
s

Samuel Michael

04/08/2021, 11:58 AM
I think I was just mistaken from the beginning, I assumed because I saw we were pulling it in that we also had wrapped it in something, turns out we are still using entirely homemade solution
At least playing with the library was fun, got to use KotlinPoet library for first time
😄 1
w

wasyl

04/08/2021, 12:01 PM
I got to use it when contributing to Apollo, so you can do that as well 😛