We’re happy to introduce an Apollo Kotlin plugin for Android Studio and IntelliJ IDEA, to help you work with the library and improve your productivity.
This preview release can be tried out today.
On-the-fly code generation
Apollo Kotlin is a strongly-typed client library that generates models from your GraphQL queries. This works thanks to a Gradle plugin that triggers the code generation at build time. Normally, after touching a graphql file, to be able to use the up-to-date generated models in your Kotlin code, you would need to manually run the codegen Gradle task.
With the IDE plugin, this is done automatically: the codegen is run in the background whenever you touch your GraphQL queries, so you can use the models immediately.
Apollo Kotlin 3 was a major version that introduced quite a few changes compared to version 2. While some of these changes require manual tweaks to the code, a lot of these can be automated. Which is what the “Migrate to Apollo Kotlin 3” action does. If you are still on version 2, now is a good time to migrate!
If you are using Apollo Kotlin 3 with the
compat codegen, which was meant to ease the migration from version 2 (and will be discontinued in the upcoming version 4 release), the plugin can also help with this: “Migrate to
When editing Kotlin code that references GraphQL queries, it is often useful to go to their definition – for instance, if you need to add a field to the selection. The natural way to do that in Android Studio is to
Cmd/Ctrl + click (or
Cmd/Ctrl + b on the keyboard) on the symbol. However without any special knowledge of Apollo Kotlin or GraphQL, this would go to the generated code, which is not as useful. Not anymore! The plugin adds target to go to the GraphQL definition:
Note that the generated code destination is still there, as it is sometimes handy to have a look at it.
We’ve also added these nifty GraphQL icons in the gutter next to operation and fragment references. Click on them to go to the definition.
To go to the Schema instead, use “Go To Type Declaration” (
Cmd/Ctrl + Shift + click, or
Cmd/Ctrl + Shift + b):
The reverse works too if you need it: “Find Usages” on your GraphQL operation will list Kotlin files referencing them:
We hope to add “Find Usages” on fields as well in the future.
More to come
We are working on adding more features and your ideas are very welcome! Please don’t hesitate to submit feature requests on the issue tracker.
Try it out!
To install the plugin:
- During the preview phase, you will need to add a dedicated plugin repository:
Manage Plugin Repositories>
https://plugins.jetbrains.com/plugins/preview/20645– If you want the cutting edge, use this “snapshots” URL instead (new versions once a week):
Marketplace> Search for “Apollo GraphQL” >
Detailed instructions are available here.
We hope this plugin will make your experience with Apollo Kotlin a delightful one and will help you build great apps. Stay tuned for more, and as always, your feedback is welcome! You can reach out on GitHub, the Apollo Community, or the Kotlin Slack!
Benoit has been writing software for 20 years, with a focus on Android since its v1. When he’s not coding, you can find him enjoying movies or geocaching.
Stay in our orbit!
Become an Apollo insider and get first access to new features, best practices, and community events. Oh, and no junk mail. Ever.
Make this article better!
Was this post helpful? Have suggestions? Consider so we can improve it for future readers ✨.