Skip to content

Commit

Permalink
feat(apollo): Add Apollo Appsync Extensions (#2907)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcreaser authored Sep 6, 2024
1 parent 8b3b259 commit 7f874ed
Show file tree
Hide file tree
Showing 62 changed files with 26,459 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/pr-title-checker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"CHECKS": {
"prefixes": ["chore: ", "refactor: ", "perf: ", "test: ", "docs: ", "release: "],
"regexp": "(fix|feat)\\((all|analytics|api|auth|core|datastore|geo|predictions|storage|notifications)\\): ",
"regexp": "(fix|feat)\\((all|analytics|api|auth|core|datastore|geo|predictions|storage|notifications|apollo)\\): ",
"regexpFlags": "",
"ignoreLabels" : ["ignore-pr-title"]
},
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/release_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ name: Prepare Next Release
on:
workflow_dispatch:
inputs:
component:
type: choice
description: Component to release
required: true
options:
- AmplifyAndroid
- ApolloExtensions
release_tag:
description: 'Release Tag'
description: 'Previous Release Tag'
required: false
type: string
env:
Expand Down Expand Up @@ -46,9 +53,10 @@ jobs:
env:
RELEASE_MANAGER_TOKEN: ${{secrets.GITHUB_TOKEN}}
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
COMPONENT: ${{ github.event.inputs.component }}
run: |
cd scripts
bundle exec fastlane android create_next_release_pr release_tag:"$RELEASE_TAG" base_branch:"$BASE_BRANCH"
bundle exec fastlane android create_next_release_pr release_tag:"$RELEASE_TAG" base_branch:"$BASE_BRANCH" release_component_target:"$COMPONENT"
- name: Check modified file content
run: |
cat gradle.properties
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ __pycache__/
.gradle/**

#amplify
.amplify/
amplify/
build/
dist/
Expand Down
3 changes: 3 additions & 0 deletions apollo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Release 1.0.0

Initial Release
59 changes: 59 additions & 0 deletions apollo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<img src="https://s3.amazonaws.com/aws-mobile-hub-images/aws-amplify-logo.png" alt="AWS Amplify" width="225">

---

# AWS AppSync Apollo Extensions for Kotlin

These libraries allows you to connect [Apollo Kotlin](https://www.apollographql.com/docs/kotlin/) v4.x to [AWS AppSync](https://aws.amazon.com/pm/appsync/).

There are two libraries available:

- `apollo-appsync`: This library implements the authorization and protocol logic for Apollo to connect to AppSync. It does not depend on Amplify, and instead leaves it to the application developer to supply tokens or signatures when using Owner or IAM-based authorization. This is the recommended library if your application does not already use Amplify.
- `apollo-appsync-amplify`: This library depends on both `apollo-appsync` and `Amplify Android`, and contains some glue classes to use Amplify to implement the authorizers for `apollo-appsync`. This is the recommended library if your application is already using Amplify.

## Usage

Add the dependency you prefer to your `build.gradle.kts` file.

```kotlin
// To only use Apollo to speak to AppSync, without using Amplify
implementation("com.amplifyframework:apollo-appsync:1.0.0")

// To connect Apollo to AppSync using your existing Amplify Gen2 Backend
implementation("com.amplifyframework:apollo-appsync-amplify:1.0.0")
```

For applications using `apollo-appsync` directly, instantiate the Endpoint and the desired Authorizer instance, and then call the Apollo builder extension.

```kotlin
val endpoint = AppSyncEndpoint("https://example1234567890123456789.appsync-api.us-east-1.amazonaws.com/graphql")
val authorizer = ApiKeyAuthorizer("[YOUR_API_KEY")

val apolloClient = ApolloClient.Builder()
.appSync(endpoint, authorizer)
.build()
```

For applications using `apollo-appsync-amplify`, you can connect directly to your Amplify Gen2 Backend using an `ApolloAmplifyConnector`. This class can create Authorizer instances that use Amplify to provide Cognito Tokens and sign requests as needed.

```kotlin
val connector = ApolloAmplifyConnector(context, AmplifyOutputs(R.raw.amplify_outputs))

val apolloClient = ApolloClient.Builder()
.appSync(connector.endpoint, connect.apiKeyAuthorizer())
.build()
```

Once you have constructed the Apollo client you can use it as normal for queries, mutations, and subscriptions to AppSync.

## Contributing

- [CONTRIBUTING.md](../CONTRIBUTING.md)

## Security

See [CONTRIBUTING](../CONTRIBUTING.md#security-issue-notifications) for more information.

## License

This project is licensed under the Apache-2.0 License.
1 change: 1 addition & 0 deletions apollo/apollo-appsync-amplify/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
28 changes: 28 additions & 0 deletions apollo/apollo-appsync-amplify/api/apollo-appsync-amplify.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public final class com/amplifyframework/apollo/appsync/ApolloAmplifyConnector {
public static final field Companion Lcom/amplifyframework/apollo/appsync/ApolloAmplifyConnector$Companion;
public fun <init> (Landroid/content/Context;Lcom/amplifyframework/core/configuration/AmplifyOutputs;)V
public final fun apiKeyAuthorizer ()Lcom/amplifyframework/apollo/appsync/authorizers/ApiKeyAuthorizer;
public final fun cognitoUserPoolAuthorizer ()Lcom/amplifyframework/apollo/appsync/authorizers/AuthTokenAuthorizer;
public static final fun fetchLatestCognitoAuthToken (Ljava/util/function/Consumer;Ljava/util/function/Consumer;)V
public final fun getApiKey ()Ljava/lang/String;
public final fun getEndpoint ()Lcom/amplifyframework/apollo/appsync/AppSyncEndpoint;
public final fun getRegion ()Ljava/lang/String;
public final fun iamAuthorizer ()Lcom/amplifyframework/apollo/appsync/authorizers/IamAuthorizer;
public static final fun signAppSyncRequest (Lcom/apollographql/apollo/api/http/HttpRequest;Ljava/lang/String;Ljava/util/function/Consumer;Ljava/util/function/Consumer;)V
}

public final class com/amplifyframework/apollo/appsync/ApolloAmplifyConnector$Companion {
public final fun fetchLatestCognitoAuthToken (Ljava/util/function/Consumer;Ljava/util/function/Consumer;)V
public final synthetic fun fetchLatestCognitoAuthToken (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun signAppSyncRequest (Lcom/apollographql/apollo/api/http/HttpRequest;Ljava/lang/String;Ljava/util/function/Consumer;Ljava/util/function/Consumer;)V
public final synthetic fun signAppSyncRequest (Lcom/apollographql/apollo/api/http/HttpRequest;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class com/amplifyframework/apollo/appsync/BuildConfig {
public static final field BUILD_TYPE Ljava/lang/String;
public static final field DEBUG Z
public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String;
public static final field VERSION_NAME Ljava/lang/String;
public fun <init> ()V
}

63 changes: 63 additions & 0 deletions apollo/apollo-appsync-amplify/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import java.util.Properties

plugins {
id("com.android.library")
id("kotlin-android")
alias(libs.plugins.apollo)
}

apply(from = rootProject.file("configuration/publishing.gradle"))

fun readVersion() = Properties().run {
file("../version.properties").inputStream().use { load(it) }
get("VERSION_NAME").toString()
}

project.setProperty("VERSION_NAME", readVersion())
group = properties["POM_GROUP"].toString()

android {
namespace = "com.amplifyframework.apollo.appsync"
defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}

apollo {
service("appsync") {
packageName.set("com.amplifyframework.apollo.graphql")
srcDir("src/androidTest/graphql")
outputDirConnection {
connectToAndroidSourceSet("androidTest")
}
}
}

dependencies {
api(project(":apollo-appsync"))
api(project(":core"))

implementation(project(":aws-auth-cognito"))
implementation(project(":aws-core"))
implementation(libs.aws.signing)

testImplementation(libs.test.junit)
testImplementation(libs.test.mockk)
testImplementation(libs.test.kotlin.coroutines)
testImplementation(libs.test.kotest.assertions)

androidTestImplementation(libs.test.junit)
androidTestImplementation(libs.test.androidx.core)
androidTestImplementation(libs.test.kotest.assertions)
androidTestImplementation(libs.test.androidx.runner)
androidTestImplementation(libs.test.kotlin.coroutines)
androidTestImplementation(libs.test.turbine)
}

android.kotlinOptions {
jvmTarget = "11"
}
Empty file.
4 changes: 4 additions & 0 deletions apollo/apollo-appsync-amplify/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POM_ARTIFACT_ID=apollo-appsync-amplify
POM_NAME=Apollo AppSync - Amplify Extensions
POM_DESCRIPTION=Allows Apollo to connect to AppSync using Amplify Framework for authorization
POM_PACKAGING=aar
21 changes: 21 additions & 0 deletions apollo/apollo-appsync-amplify/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx ampx sandbox
Loading

0 comments on commit 7f874ed

Please sign in to comment.