Skip to content

Commit 6481213

Browse files
committed
Add a AS/IJ plugin doc #5123
1 parent 6acd073 commit 6481213

File tree

7 files changed

+90
-3
lines changed

7 files changed

+90
-3
lines changed

docs/source/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"Batching operations": "/advanced/query-batching"
6262
},
6363
"Development & Testing": {
64-
"Overview": "/testing/overview",
64+
"Android Studio plugin": "/testing/android-studio-plugin",
65+
"Testing overview": "/testing/overview",
6566
"Mocking HTTP responses": "/testing/mocking-http-responses",
6667
"Mocking GraphQL responses": "/testing/mocking-graphql-responses",
6768
"Data builders": "/testing/data-builders",

docs/source/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ As the code generated by Apollo Kotlin doesn't use any reflection, it can safely
154154

155155
An experimental [plugin for Android Studio and IntelliJ](https://plugins.jetbrains.com/plugin/20645-apollo-graphql) is available to help you work with Apollo Kotlin, providing automatic code generation, integration with the [GraphQL IntelliJ Plugin](https://plugins.jetbrains.com/plugin/8097-js-graphql), navigation to GraphQL definitions, migration helpers, and more.
156156

157-
Installation instructions and more information can be found [here](https://github.com/apollographql/apollo-kotlin/tree/main/intellij-plugin).
157+
Installation instructions and more information can be found [here](testing/android-studio-plugin).
158158

159159
## Releases
160160

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: Android Studio / IntelliJ plugin
3+
---
4+
5+
To help your day-to-day development with Apollo Kotlin, a plugin for Android Studio and IntelliJ is available.
6+
7+
## Installation
8+
9+
The plugin is available on the JetBrains plugin repository. To install it from the IDE, go to
10+
<kbd>Settings</kbd> | <kbd>Plugins</kbd> | <kbd>Marketplace</kbd> | search for "Apollo GraphQL" | <kbd>Install</kbd>
11+
12+
At the time of writing, the plugin is supported on:
13+
14+
- IntelliJ 2022.2 and above
15+
- Android Studio 2022.2 (Flamingo) and above
16+
17+
Please check the [plugin page](https://plugins.jetbrains.com/plugin/20645-apollo-graphql) for up to date information.
18+
19+
## Features
20+
21+
### Automatic code generation
22+
23+
The plugin automatically generates models whenever GraphQL files change.
24+
This means you don't need to manually run `./gradlew generateApolloSources` after editing the files.
25+
26+
Note: this works by running Gradle in continuous mode, and can be disabled in the plugin settings.
27+
28+
### Integration with the GraphQL IntelliJ Plugin
29+
30+
The plugin depends on and integrates with the [GraphQL IntelliJ Plugin](https://plugins.jetbrains.com/plugin/8097-js-graphql).
31+
The file structure of the Apollo project is automatically contributed, so there is no need to create a `graphql.config.yml` / `.graphqlconfig` file.
32+
33+
### Navigation
34+
35+
#### Kotlin → GraphQL
36+
37+
When editing Kotlin code, <img src="images/gutter-icon.png" alt="Gutter icon" width="16" valign="middle" style="display: inline; margin: 2px;"/> icons will show next to references to generated operation and fragment classes.
38+
Clicking on them will navigate to the corresponding GraphQL definition.
39+
40+
You can also go to the GraphQL definition with <kbd>Cmd</kbd> Click (Mac) or <kbd>Ctrl</kbd> Click (Windows / Linux) on an operation, field, enum, etc.
41+
42+
#### GraphQL → Kotlin
43+
44+
You can search for code usages of a GraphQL operation, fragment, enum type/value and input type/field, with right click | <kbd>Find Usages</kbd>.
45+
46+
### Unused operations / fields
47+
48+
In GraphQL files, operations and fields are shown in grey if the corresponding generated code is not used in your project.
49+
50+
### Migration helpers
51+
52+
In the <kbd>Refactor</kbd> | <kbd>Apollo</kbd> menu, you can find helpers to migrate your project:
53+
54+
- Apollo Android 2.x → Apollo Kotlin 3.x
55+
- `compat` codegen → `operationBased` codegen
56+
- Apollo Kotlin 3.x → Apollo Kotlin 4.x
57+
58+
Note: while these helpers will automatically update your code when possible, there are some cases where this isn't possible and manual changes are required.
59+
Please refer to the migration guides ([3.x](../migration/3.0/), [4.x](../migration/4.0/)) when upgrading.
60+
61+
### Open in Apollo Sandbox
62+
63+
You can open a GraphQL file in [Apollo Sandbox](https://studio.apollographql.com/sandbox/explorer) with right click | <kbd>Open in</kbd> | <kbd>Apollo Sandbox</kbd>.
64+
This is a handy way to share operations with coworkers for instance. There, they will be able to execute the operation and see the result.
65+
66+
This is also accessible from the <img src="images/open-in-sandbox.png" alt="Sandbox icon" width="16" valign="middle" style="display: inline; margin: 2px;"/> button at the top of the editor.
67+
68+
### High latency fields
69+
70+
If your project uses Apollo GraphOS, the plugin can use the collected metrics (["Field Insights"](https://www.apollographql.com/docs/graphos/metrics/field-usage)) and report a warning on fields that have a high latency.
71+
72+
<img src="images/high-latency-field-editor.png" width="400" alt="High latency in editor"/>
73+
74+
By default, fields with a latency above 100ms will be highlighted. You can change this threshold in <kbd>Settings</kbd> | <kbd>Editor</kbd> | <kbd>Inspections</kbd> | <kbd>GraphQL</kbd> | <kbd>Apollo GraphOS</kbd> | <kbd>High latency field</kbd>.
75+
76+
A quick fix is available to encapsulate the field in a fragment with the [`@defer`](../fetching/defer) directive.
77+
78+
For the plugin to be able to fetch the metrics, you need to configure your project with its [Apollo GraphOS API key](https://www.apollographql.com/docs/graphos/api-keys/). To do this, go to the plugin's settings: <kbd>Settings</kbd> | <kbd>Languages & Frameworks</kbd> | <kbd>GraphQL</kbd> | <kbd>Apollo Kotlin</kbd>. Here you can find the <kbd>API keys</kbd> table where you can add:
79+
- API key: should start with `service:` or `user:`
80+
- Graph ID: can be found on your graph page in Apollo Studio or is filled automatically if you provide a `service:` API key
81+
82+
## Weekly snapshots
83+
84+
If you wish to try the latest features, you can install the weekly snapshots. To do so, add the following repository in <kbd>Settings</kbd> | <kbd>Plugins</kbd> | <kbd>⚙</kbd>️ | <kbd>Manage Plugin Repositories</kbd> | <kbd>+</kbd>: `https://raw.githubusercontent.com/apollographql/apollo-kotlin/main/intellij-plugin/snapshots/plugins.xml`.
85+
86+
Then installing the plugin by searching "Apollo GraphQL" in the Marketplace will install the latest snapshot.
1.34 KB
Loading
65.5 KB
Loading
2.05 KB
Loading

intellij-plugin/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pluginId=com.apollographql.ijplugin
66
pluginRepositoryUrl=https://github.com/apollographql/apollo-kotlin
77

88

9-
# XXX Do update the supported versions in the README.md file when updating these values!
9+
# XXX Do update the supported versions in the README.md, and in docs/source/testing/android-studio-plugin.mdx file when updating these values!
1010
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1111
# for insight into build numbers and IntelliJ Platform versions.
1212
pluginSinceBuild=222

0 commit comments

Comments
 (0)