-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apollo): Add Apollo Appsync Extensions (#2907)
- Loading branch information
1 parent
8b3b259
commit 7f874ed
Showing
62 changed files
with
26,459 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,7 @@ __pycache__/ | |
.gradle/** | ||
|
||
#amplify | ||
.amplify/ | ||
amplify/ | ||
build/ | ||
dist/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Release 1.0.0 | ||
|
||
Initial Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
28 changes: 28 additions & 0 deletions
28
apollo/apollo-appsync-amplify/api/apollo-appsync-amplify.api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
1 change: 1 addition & 0 deletions
1
apollo/apollo-appsync-amplify/src/androidTest/backend/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx ampx sandbox |
Oops, something went wrong.