website/src/pages/plugins/java/java-apollo-android.mdx
import { Callout } from '@theguild/components' import { PluginApiDocs, PluginHeader } from '@/components/plugin' import { pluginGetStaticProps } from '@/lib/plugin-get-static-props' export const getStaticProps = pluginGetStaticProps(__filename)
<PluginHeader />To get started with these plugins and preset, make sure you have the following installed:
Run the following in your Android project:
npm init --yes
npm install graphql
npm install -D @graphql-codegen/cli @graphql-codegen/java-apollo-android
Then, create codegen.yml with the following configuration:
schema: POINT_TO_YOUR_SCHEMA
documents: POINT_TO_YOUR_GRAPHQL_OPERATIONS
generates:
./app/src/main/java/:
preset: java-apollo-android
config:
package: 'com.my.app.generated.graphql'
fragmentPackage: 'com.my.app.generated.graphql'
typePackage: 'type'
plugins:
- java-apollo-android
<Callout>Also, make sure to add node_modules to your .gitignore file.</Callout>
To integrate with your Gradle build, you can add the following to your app Gradle file:
preBuild.doFirst {
def proc = "yarn graphql-codegen".execute()
proc.waitForProcessOutput(System.out, System.err)
}
build.dependsOn preBuild
This will make sure to run and generate output before each time you build your project.
You can find a repository with a working example using AppSync.
<PluginApiDocs />