Skip to content

Commit 7f874ed

Browse files
authored
feat(apollo): Add Apollo Appsync Extensions (#2907)
1 parent 8b3b259 commit 7f874ed

File tree

62 files changed

+26459
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+26459
-36
lines changed

.github/pr-title-checker-config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"CHECKS": {
77
"prefixes": ["chore: ", "refactor: ", "perf: ", "test: ", "docs: ", "release: "],
8-
"regexp": "(fix|feat)\\((all|analytics|api|auth|core|datastore|geo|predictions|storage|notifications)\\): ",
8+
"regexp": "(fix|feat)\\((all|analytics|api|auth|core|datastore|geo|predictions|storage|notifications|apollo)\\): ",
99
"regexpFlags": "",
1010
"ignoreLabels" : ["ignore-pr-title"]
1111
},

.github/workflows/release_pr.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ name: Prepare Next Release
22
on:
33
workflow_dispatch:
44
inputs:
5+
component:
6+
type: choice
7+
description: Component to release
8+
required: true
9+
options:
10+
- AmplifyAndroid
11+
- ApolloExtensions
512
release_tag:
6-
description: 'Release Tag'
13+
description: 'Previous Release Tag'
714
required: false
815
type: string
916
env:
@@ -46,9 +53,10 @@ jobs:
4653
env:
4754
RELEASE_MANAGER_TOKEN: ${{secrets.GITHUB_TOKEN}}
4855
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
56+
COMPONENT: ${{ github.event.inputs.component }}
4957
run: |
5058
cd scripts
51-
bundle exec fastlane android create_next_release_pr release_tag:"$RELEASE_TAG" base_branch:"$BASE_BRANCH"
59+
bundle exec fastlane android create_next_release_pr release_tag:"$RELEASE_TAG" base_branch:"$BASE_BRANCH" release_component_target:"$COMPONENT"
5260
- name: Check modified file content
5361
run: |
5462
cat gradle.properties

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ __pycache__/
9696
.gradle/**
9797

9898
#amplify
99+
.amplify/
99100
amplify/
100101
build/
101102
dist/

apollo/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Release 1.0.0
2+
3+
Initial Release

apollo/README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<img src="https://s3.amazonaws.com/aws-mobile-hub-images/aws-amplify-logo.png" alt="AWS Amplify" width="225">
2+
3+
---
4+
5+
# AWS AppSync Apollo Extensions for Kotlin
6+
7+
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/).
8+
9+
There are two libraries available:
10+
11+
- `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.
12+
- `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.
13+
14+
## Usage
15+
16+
Add the dependency you prefer to your `build.gradle.kts` file.
17+
18+
```kotlin
19+
// To only use Apollo to speak to AppSync, without using Amplify
20+
implementation("com.amplifyframework:apollo-appsync:1.0.0")
21+
22+
// To connect Apollo to AppSync using your existing Amplify Gen2 Backend
23+
implementation("com.amplifyframework:apollo-appsync-amplify:1.0.0")
24+
```
25+
26+
For applications using `apollo-appsync` directly, instantiate the Endpoint and the desired Authorizer instance, and then call the Apollo builder extension.
27+
28+
```kotlin
29+
val endpoint = AppSyncEndpoint("https://example1234567890123456789.appsync-api.us-east-1.amazonaws.com/graphql")
30+
val authorizer = ApiKeyAuthorizer("[YOUR_API_KEY")
31+
32+
val apolloClient = ApolloClient.Builder()
33+
.appSync(endpoint, authorizer)
34+
.build()
35+
```
36+
37+
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.
38+
39+
```kotlin
40+
val connector = ApolloAmplifyConnector(context, AmplifyOutputs(R.raw.amplify_outputs))
41+
42+
val apolloClient = ApolloClient.Builder()
43+
.appSync(connector.endpoint, connect.apiKeyAuthorizer())
44+
.build()
45+
```
46+
47+
Once you have constructed the Apollo client you can use it as normal for queries, mutations, and subscriptions to AppSync.
48+
49+
## Contributing
50+
51+
- [CONTRIBUTING.md](../CONTRIBUTING.md)
52+
53+
## Security
54+
55+
See [CONTRIBUTING](../CONTRIBUTING.md#security-issue-notifications) for more information.
56+
57+
## License
58+
59+
This project is licensed under the Apache-2.0 License.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public final class com/amplifyframework/apollo/appsync/ApolloAmplifyConnector {
2+
public static final field Companion Lcom/amplifyframework/apollo/appsync/ApolloAmplifyConnector$Companion;
3+
public fun <init> (Landroid/content/Context;Lcom/amplifyframework/core/configuration/AmplifyOutputs;)V
4+
public final fun apiKeyAuthorizer ()Lcom/amplifyframework/apollo/appsync/authorizers/ApiKeyAuthorizer;
5+
public final fun cognitoUserPoolAuthorizer ()Lcom/amplifyframework/apollo/appsync/authorizers/AuthTokenAuthorizer;
6+
public static final fun fetchLatestCognitoAuthToken (Ljava/util/function/Consumer;Ljava/util/function/Consumer;)V
7+
public final fun getApiKey ()Ljava/lang/String;
8+
public final fun getEndpoint ()Lcom/amplifyframework/apollo/appsync/AppSyncEndpoint;
9+
public final fun getRegion ()Ljava/lang/String;
10+
public final fun iamAuthorizer ()Lcom/amplifyframework/apollo/appsync/authorizers/IamAuthorizer;
11+
public static final fun signAppSyncRequest (Lcom/apollographql/apollo/api/http/HttpRequest;Ljava/lang/String;Ljava/util/function/Consumer;Ljava/util/function/Consumer;)V
12+
}
13+
14+
public final class com/amplifyframework/apollo/appsync/ApolloAmplifyConnector$Companion {
15+
public final fun fetchLatestCognitoAuthToken (Ljava/util/function/Consumer;Ljava/util/function/Consumer;)V
16+
public final synthetic fun fetchLatestCognitoAuthToken (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
17+
public final fun signAppSyncRequest (Lcom/apollographql/apollo/api/http/HttpRequest;Ljava/lang/String;Ljava/util/function/Consumer;Ljava/util/function/Consumer;)V
18+
public final synthetic fun signAppSyncRequest (Lcom/apollographql/apollo/api/http/HttpRequest;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
19+
}
20+
21+
public final class com/amplifyframework/apollo/appsync/BuildConfig {
22+
public static final field BUILD_TYPE Ljava/lang/String;
23+
public static final field DEBUG Z
24+
public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String;
25+
public static final field VERSION_NAME Ljava/lang/String;
26+
public fun <init> ()V
27+
}
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import java.util.Properties
2+
3+
plugins {
4+
id("com.android.library")
5+
id("kotlin-android")
6+
alias(libs.plugins.apollo)
7+
}
8+
9+
apply(from = rootProject.file("configuration/publishing.gradle"))
10+
11+
fun readVersion() = Properties().run {
12+
file("../version.properties").inputStream().use { load(it) }
13+
get("VERSION_NAME").toString()
14+
}
15+
16+
project.setProperty("VERSION_NAME", readVersion())
17+
group = properties["POM_GROUP"].toString()
18+
19+
android {
20+
namespace = "com.amplifyframework.apollo.appsync"
21+
defaultConfig {
22+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
23+
}
24+
25+
testOptions {
26+
execution = "ANDROIDX_TEST_ORCHESTRATOR"
27+
}
28+
}
29+
30+
apollo {
31+
service("appsync") {
32+
packageName.set("com.amplifyframework.apollo.graphql")
33+
srcDir("src/androidTest/graphql")
34+
outputDirConnection {
35+
connectToAndroidSourceSet("androidTest")
36+
}
37+
}
38+
}
39+
40+
dependencies {
41+
api(project(":apollo-appsync"))
42+
api(project(":core"))
43+
44+
implementation(project(":aws-auth-cognito"))
45+
implementation(project(":aws-core"))
46+
implementation(libs.aws.signing)
47+
48+
testImplementation(libs.test.junit)
49+
testImplementation(libs.test.mockk)
50+
testImplementation(libs.test.kotlin.coroutines)
51+
testImplementation(libs.test.kotest.assertions)
52+
53+
androidTestImplementation(libs.test.junit)
54+
androidTestImplementation(libs.test.androidx.core)
55+
androidTestImplementation(libs.test.kotest.assertions)
56+
androidTestImplementation(libs.test.androidx.runner)
57+
androidTestImplementation(libs.test.kotlin.coroutines)
58+
androidTestImplementation(libs.test.turbine)
59+
}
60+
61+
android.kotlinOptions {
62+
jvmTarget = "11"
63+
}

apollo/apollo-appsync-amplify/consumer-rules.pro

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
POM_ARTIFACT_ID=apollo-appsync-amplify
2+
POM_NAME=Apollo AppSync - Amplify Extensions
3+
POM_DESCRIPTION=Allows Apollo to connect to AppSync using Amplify Framework for authorization
4+
POM_PACKAGING=aar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx ampx sandbox

0 commit comments

Comments
 (0)