Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a AS/IJ plugin doc #5123

Merged
merged 6 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/source/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@
"Batching operations": "/advanced/query-batching"
},
"Development & Testing": {
"Overview": "/testing/overview",
"Testing overview": "/testing/overview",
"Mocking HTTP responses": "/testing/mocking-http-responses",
"Mocking GraphQL responses": "/testing/mocking-graphql-responses",
"Data builders": "/testing/data-builders",
"UI Tests": "/testing/ui-tests"
"UI Tests": "/testing/ui-tests",
"Android Studio plugin": "/testing/android-studio-plugin"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move it up before testing in the list because you should set this up before you start testing. Also update the "Get Started" to link to this page?

},
"Advanced": {
"Uploading files": "/advanced/upload",
Expand Down
84 changes: 84 additions & 0 deletions docs/source/testing/android-studio-plugin.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
title: Android Studio / IntelliJ plugin
---

To help your day-to-day development with Apollo Kotlin, a plugin for Android Studio and IntelliJ is available.

## Installation

The plugin is available on the JetBrains plugin repository. To install it from the IDE, go to
<kbd>Settings</kbd> | <kbd>Plugins</kbd> | <kbd>Marketplace</kbd> | search for "Apollo GraphQL" | <kbd>Install</kbd>

The plugin is supported on:

- IntelliJ 2022.2 and above
- Android Studio 2022.2 (Flamingo) and above
BoD marked this conversation as resolved.
Show resolved Hide resolved

## Features

### Automatic code generation

The plugin automatically generates models whenever GraphQL files change.
This means you don't need to manually run `./gradlew generateApolloSources` after editing the files.

Note: this works by running Gradle in continuous mode, and can be disabled in the plugin settings.

### Integration with the GraphQL IntelliJ Plugin

The plugin depends on and integrates with the [GraphQL IntelliJ Plugin](https://plugins.jetbrains.com/plugin/8097-js-graphql).
The file structure of the Apollo project is automatically contributed, so there is no need to create a `graphql.config.yml` / `.graphqlconfig` file.

### Navigation

#### Kotlin → GraphQL

When editing Kotlin code, <img src="images/gutter-icon.png" alt="Gutter icon" width="16" valign="top"/> icons will show next to references to generated operation and fragment classes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline images do not work :(. I'm no css expert but maybe a display: inline-block; would work here?

Screenshot 2023-07-25 at 13 49 30

Clicking on them will navigate to the corresponding GraphQL definition.

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.

#### GraphQL → Kotlin

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>.

### Unused operations / fields

In GraphQL files, operations and fields are shown in grey if the corresponding generated code is not used in your project.

### Migration helpers

In the <kbd>Refactor</kbd> | <kbd>Apollo</kbd> menu, you can find helpers to migrate your project:

- Apollo Android 2.x → Apollo Kotlin 3.x
- `compat` codegen → `operationBased` codegen
- Apollo Kotlin 3.x → Apollo Kotlin 4.x

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.
Please refer to the migration guides ([3.x](../migration/3.0/), [4.x](../migration/4.0/)) when upgrading.

### Open in Apollo Sandbox

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>.
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.

This is also accessible from the <img src="images/open-in-sandbox.png" alt="Sandbox icon" width="16" valign="top"/> button at the top of the editor.

### High latency fields

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.

<img src="images/high-latency-field-editor.png" width="400" alt="High latency in editor"/>

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>.

A quick fix is available to encapsulate the field in a fragment with the [`@defer`](../fetching/defer) directive.

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:
- API key: should start with `service:` or `user:`
- Graph ID: can be found on your graph page in Apollo Studio
BoD marked this conversation as resolved.
Show resolved Hide resolved

## Weekly snapshots

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`.

Then installing the plugin by searching "Apollo GraphQL" in the Marketplace will install the latest snapshot.
Binary file added docs/source/testing/images/gutter-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/testing/images/open-in-sandbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.