├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── usage-question.md ├── PULL_REQUEST_TEMPLATE.md ├── stale.yml └── workflows │ ├── notify_comments.yml │ └── release_pr.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── TESTING.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── graphql │ ├── com │ │ └── amazonaws │ │ │ └── amplify │ │ │ └── generated │ │ │ └── graphql │ │ │ ├── mutations.graphql │ │ │ ├── queries.graphql │ │ │ └── subscriptions.graphql │ └── schema.json │ ├── java │ └── com │ │ └── amazonaws │ │ └── postsapp │ │ ├── AddPostActivity.java │ │ ├── ClientFactory.java │ │ ├── Constants.java │ │ ├── PostsActivity.java │ │ ├── PostsAdapter.java │ │ └── UpdatePostActivity.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_add_post.xml │ ├── activity_posts.xml │ ├── activity_update_post.xml │ └── post.xml │ ├── menu │ └── menu_save.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── aws-android-sdk-appsync-api ├── .gitignore ├── build.gradle ├── gradle.properties └── src │ └── main │ └── java │ └── com │ └── apollographql │ └── apollo │ ├── Logger.java │ ├── api │ ├── Error.java │ ├── FragmentResponseFieldMapper.java │ ├── GraphqlFragment.java │ ├── Input.java │ ├── InputFieldMarshaller.java │ ├── InputFieldWriter.java │ ├── InputType.java │ ├── Mutation.java │ ├── Operation.java │ ├── OperationName.java │ ├── Query.java │ ├── Response.java │ ├── ResponseField.java │ ├── ResponseFieldMapper.java │ ├── ResponseFieldMarshaller.java │ ├── ResponseReader.java │ ├── ResponseWriter.java │ ├── S3InputObjectInterface.java │ ├── S3ObjectInterface.java │ ├── S3ObjectManager.java │ ├── ScalarType.java │ ├── Subscription.java │ ├── cache │ │ └── http │ │ │ ├── HttpCache.java │ │ │ ├── HttpCachePolicy.java │ │ │ ├── HttpCacheRecord.java │ │ │ ├── HttpCacheRecordEditor.java │ │ │ └── HttpCacheStore.java │ └── internal │ │ ├── Absent.java │ │ ├── Action.java │ │ ├── Function.java │ │ ├── Functions.java │ │ ├── Mutator.java │ │ ├── Optional.java │ │ ├── Present.java │ │ ├── UnmodifiableMapBuilder.java │ │ └── Utils.java │ └── internal │ └── ApolloLogger.java ├── aws-android-sdk-appsync-compiler ├── .gitignore ├── build.gradle ├── gradle.properties └── src │ ├── generated │ └── kotlin │ │ └── com │ │ └── apollographql │ │ └── android │ │ └── Version.kt │ └── main │ └── kotlin │ └── com │ └── apollographql │ └── apollo │ └── compiler │ ├── Annotations.kt │ ├── BuilderTypeSpecBuilder.kt │ ├── ClassNames.kt │ ├── CustomEnumTypeSpecBuilder.kt │ ├── FragmentsResponseMapperBuilder.kt │ ├── GraphQLCompiler.kt │ ├── Inflector.kt │ ├── InputFieldSpec.kt │ ├── InputTypeSpecBuilder.kt │ ├── JavaTypeResolver.kt │ ├── NullableValueType.kt │ ├── OperationTypeSpecBuilder.kt │ ├── ResponseFieldSpec.kt │ ├── SchemaTypeSpecBuilder.kt │ ├── Util.kt │ ├── VariablesTypeSpecBuilder.kt │ └── ir │ ├── CodeGenerationContext.kt │ ├── CodeGenerationIR.kt │ ├── CodeGenerator.kt │ ├── Condition.kt │ ├── Field.kt │ ├── Fragment.kt │ ├── InlineFragment.kt │ ├── Operation.kt │ ├── ScalarType.kt │ ├── TypeDeclaration.kt │ ├── TypeDeclarationField.kt │ ├── TypeDeclarationValue.kt │ └── Variable.kt ├── aws-android-sdk-appsync-gradle-plugin ├── .gitignore ├── build.gradle ├── gradle.properties └── src │ └── main │ ├── groovy │ └── com │ │ └── apollographql │ │ └── apollo │ │ └── gradle │ │ └── ApolloPlugin.groovy │ ├── java │ └── com │ │ └── apollographql │ │ └── apollo │ │ └── gradle │ │ ├── ApolloClassGenTask.java │ │ ├── ApolloCodeGenInstallTask.java │ │ ├── ApolloCodegenArgs.java │ │ ├── ApolloExtension.java │ │ ├── ApolloIRGenTask.java │ │ ├── ApolloSchemaIntrospectionTask.java │ │ └── Utils.java │ └── resources │ └── META-INF │ └── gradle-plugins │ └── com.amazonaws.appsync.properties ├── aws-android-sdk-appsync-runtime ├── .gitignore ├── build.gradle ├── gradle.properties └── src │ └── main │ └── java │ └── com │ ├── amazonaws │ └── mobileconnectors │ │ └── appsync │ │ ├── AppSyncMutationCall.java │ │ ├── AppSyncPrefetch.java │ │ ├── AppSyncQueryCall.java │ │ ├── AppSyncQueryWatcher.java │ │ ├── AppSyncSubscriptionCall.java │ │ ├── AppSyncSubscriptionListener.java │ │ ├── fetcher │ │ └── AppSyncResponseFetchers.java │ │ └── subscription │ │ └── SubscriptionResponse.java │ └── apollographql │ └── apollo │ ├── ApolloClient.java │ ├── CustomTypeAdapter.java │ ├── GraphQLCall.java │ ├── IdleResourceCallback.java │ ├── cache │ ├── CacheHeaders.java │ ├── GraphQLCacheHeaders.java │ └── normalized │ │ ├── ApolloStore.java │ │ ├── CacheKey.java │ │ ├── CacheKeyResolver.java │ │ ├── CacheReference.java │ │ ├── GraphQLStoreOperation.java │ │ ├── NormalizedCache.java │ │ ├── NormalizedCacheFactory.java │ │ ├── OptimisticNormalizedCache.java │ │ ├── Record.java │ │ ├── RecordFieldJsonAdapter.java │ │ ├── RecordSet.java │ │ └── lru │ │ ├── EvictionPolicy.java │ │ ├── LruNormalizedCache.java │ │ └── LruNormalizedCacheFactory.java │ ├── exception │ ├── ApolloCanceledException.java │ ├── ApolloException.java │ ├── ApolloHttpException.java │ ├── ApolloNetworkException.java │ └── ApolloParseException.java │ ├── fetcher │ └── ResponseFetcher.java │ ├── interceptor │ ├── ApolloInterceptor.java │ └── ApolloInterceptorChain.java │ ├── internal │ ├── ApolloCallTracker.java │ ├── CallState.java │ ├── QueryReFetcher.java │ ├── RealAppSyncCall.java │ ├── RealAppSyncPrefetch.java │ ├── RealAppSyncQueryWatcher.java │ ├── RealAppSyncSubscriptionCall.java │ ├── ResponseFieldMapperFactory.java │ ├── cache │ │ └── normalized │ │ │ ├── CacheKeyBuilder.java │ │ │ ├── CacheResponseWriter.java │ │ │ ├── NoOpApolloStore.java │ │ │ ├── ReadableStore.java │ │ │ ├── RealAppSyncStore.java │ │ │ ├── RealCacheKeyBuilder.java │ │ │ ├── RecordWeigher.java │ │ │ ├── ResponseNormalizer.java │ │ │ ├── Transaction.java │ │ │ └── WriteableStore.java │ ├── fetcher │ │ ├── CacheAndNetworkFetcher.java │ │ ├── CacheFirstFetcher.java │ │ ├── CacheOnlyFetcher.java │ │ ├── NetworkFirstFetcher.java │ │ └── NetworkOnlyFetcher.java │ ├── field │ │ ├── CacheFieldValueResolver.java │ │ ├── FieldValueResolver.java │ │ └── MapFieldValueResolver.java │ ├── interceptor │ │ ├── ApolloCacheInterceptor.java │ │ ├── ApolloParseInterceptor.java │ │ ├── ApolloServerInterceptor.java │ │ ├── AppSyncSubscriptionInterceptor.java │ │ └── RealApolloInterceptorChain.java │ ├── json │ │ ├── ApolloJsonReader.java │ │ ├── BufferedSourceJsonReader.java │ │ ├── CacheJsonStreamReader.java │ │ ├── InputFieldJsonWriter.java │ │ ├── JsonReader.java │ │ ├── JsonScope.java │ │ ├── JsonUtf8Writer.java │ │ ├── JsonWriter.java │ │ ├── ResponseJsonStreamReader.java │ │ ├── SortedInputFieldMapWriter.java │ │ └── Utils.java │ ├── response │ │ ├── OperationResponseParser.java │ │ ├── RealResponseReader.java │ │ ├── ResponseReaderShadow.java │ │ └── ScalarTypeAdapters.java │ ├── subscription │ │ ├── NoOpSubscriptionManager.java │ │ └── SubscriptionManager.java │ └── util │ │ ├── Cancelable.java │ │ └── SimpleStack.java │ └── json │ ├── JsonDataException.java │ └── JsonEncodingException.java ├── aws-android-sdk-appsync-tests ├── .gitignore ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── proguard-rules.pro ├── settings.gradle └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── amazonaws │ │ └── mobileconnectors │ │ └── appsync │ │ ├── SyncStore.java │ │ ├── client │ │ ├── AWSAppSyncClients.java │ │ ├── DelegatingGraphQLCallback.java │ │ ├── LatchedGraphQLCallback.java │ │ ├── LatchedSubscriptionCallback.java │ │ ├── LoggingPersistentMutationsCallback.java │ │ ├── NoOpGraphQLCallback.java │ │ ├── TestConflictResolver.java │ │ └── package-info.java │ │ ├── identity │ │ ├── CustomCognitoUserPool.java │ │ ├── DelayedCognitoCredentialsProvider.java │ │ ├── DelegatingMobileClientCallback.java │ │ ├── LatchedMobileClientCallback.java │ │ ├── TestAWSMobileClient.java │ │ └── package-info.java │ │ ├── models │ │ ├── Posts.java │ │ └── package-info.java │ │ ├── tests │ │ ├── ComplexObjectsInstrumentationTests.java │ │ ├── ConflictManagementInstrumentationTest.java │ │ ├── MultiClientInstrumentationTest.java │ │ ├── QueryInstrumentationTest.java │ │ ├── SubscriptionInstrumentationTest.java │ │ └── package-info.java │ │ └── util │ │ ├── AirplaneMode.java │ │ ├── Await.java │ │ ├── Consumer.java │ │ ├── DataFile.java │ │ ├── InternetConnectivity.java │ │ ├── JsonExtract.java │ │ ├── RetryStrategies.java │ │ ├── Sleep.java │ │ └── package-info.java │ └── main │ ├── AndroidManifest.xml │ ├── assets │ ├── .gitkeep │ ├── Mutation.updateArticle.req.vtl │ ├── awsconfiguration.json.enc │ └── schema.graphql │ ├── graphql │ └── com │ │ └── amazonaws │ │ └── mobileconnectors │ │ └── appsync │ │ └── demo │ │ ├── posts.graphql │ │ └── schema.json │ └── res │ ├── raw │ └── awsconfiguration.json │ └── values │ └── strings.xml ├── aws-android-sdk-appsync ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── .gitkeep │ └── java │ │ └── com │ │ ├── amazonaws │ │ └── mobileconnectors │ │ │ └── appsync │ │ │ ├── AWSAppSyncAppLifecycleObserver.java │ │ │ ├── AWSAppSyncClient.java │ │ │ ├── AWSAppSyncClientException.java │ │ │ ├── AWSAppSyncDeltaSync.java │ │ │ ├── AWSAppSyncDeltaSyncDBOperations.java │ │ │ ├── AWSAppSyncDeltaSyncSqlHelper.java │ │ │ ├── ApolloResponseBuilder.java │ │ │ ├── AppSyncCallback.java │ │ │ ├── AppSyncComplexObjectsInterceptor.java │ │ │ ├── AppSyncCustomNetworkInvoker.java │ │ │ ├── AppSyncMutationQueueInterceptor.java │ │ │ ├── AppSyncMutationSqlCacheOperations.java │ │ │ ├── AppSyncMutationsSqlHelper.java │ │ │ ├── AppSyncOfflineMutationInterceptor.java │ │ │ ├── AppSyncOfflineMutationManager.java │ │ │ ├── AppSyncOptimisticUpdateInterceptor.java │ │ │ ├── AppSyncPrefetchCallback.java │ │ │ ├── AppSyncWebSocketSubscriptionCall.java │ │ │ ├── ClearCacheException.java │ │ │ ├── ClearCacheOptions.java │ │ │ ├── ConflictMutation.java │ │ │ ├── ConflictResolutionFailedException.java │ │ │ ├── ConflictResolutionHandler.java │ │ │ ├── ConflictResolverInterface.java │ │ │ ├── ConnectivityWatcher.java │ │ │ ├── DomainType.java │ │ │ ├── InMemoryOfflineMutationManager.java │ │ │ ├── InMemoryOfflineMutationObject.java │ │ │ ├── MessageNumberUtil.java │ │ │ ├── MutationInfoUtil.java │ │ │ ├── PersistentMutationsCallback.java │ │ │ ├── PersistentMutationsError.java │ │ │ ├── PersistentMutationsResponse.java │ │ │ ├── PersistentOfflineMutationManager.java │ │ │ ├── PersistentOfflineMutationObject.java │ │ │ ├── S3ObjectManagerImplementation.java │ │ │ ├── SubscriptionAuthorizer.java │ │ │ ├── TimeoutWatchdog.java │ │ │ ├── WebSocketConnectionManager.java │ │ │ ├── cache │ │ │ └── normalized │ │ │ │ ├── AppSyncStore.java │ │ │ │ └── sql │ │ │ │ └── AppSyncSqlHelper.java │ │ │ ├── retry │ │ │ └── RetryInterceptor.java │ │ │ ├── sigv4 │ │ │ ├── APIKeyAuthProvider.java │ │ │ ├── AWSLambdaAuthProvider.java │ │ │ ├── AppSyncSigV4SignerInterceptor.java │ │ │ ├── AppSyncV4Signer.java │ │ │ ├── BasicAPIKeyAuthProvider.java │ │ │ ├── BasicCognitoUserPoolsAuthProvider.java │ │ │ ├── CognitoUserPoolsAuthProvider.java │ │ │ └── OidcAuthProvider.java │ │ │ ├── subscription │ │ │ ├── AppSyncSubscription.java │ │ │ ├── RealSubscriptionManager.java │ │ │ ├── SubscriptionCallback.java │ │ │ ├── SubscriptionClient.java │ │ │ ├── SubscriptionClientCallback.java │ │ │ ├── SubscriptionDisconnectedException.java │ │ │ ├── SubscriptionListener.java │ │ │ ├── SubscriptionObject.java │ │ │ └── mqtt │ │ │ │ ├── AppSyncMqttPersistence.java │ │ │ │ └── MqttSubscriptionClient.java │ │ │ └── utils │ │ │ └── StringUtils.java │ │ └── apollographql │ │ └── apollo │ │ └── cache │ │ └── normalized │ │ └── sql │ │ ├── SqlNormalizedCache.java │ │ └── SqlNormalizedCacheFactory.java │ └── test │ ├── java │ └── com │ │ └── amazonaws │ │ └── mobileconnectors │ │ └── appsync │ │ ├── AppSyncClientUnitTest.java │ │ ├── DomainTypeTest.java │ │ ├── TimeoutWatchdogTest.java │ │ ├── retry │ │ └── RetryInterceptorTest.java │ │ └── util │ │ └── Await.java │ └── resources │ └── mockito-extensions │ └── org.mockito.plugins.MockMaker ├── build-support ├── Gemfile ├── Gemfile.lock └── fastlane │ ├── Appfile │ ├── Fastfile │ └── Pluginfile ├── build.gradle ├── gradle-mvn-push.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @awslabs/amplify-android 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Environment(please complete the following information):** 24 | - AppSync SDK Version: [e.g. 2.6.25] 25 | 26 | **Device Information (please complete the following information):** 27 | - Device: [e.g. Pixel XL, Simulator] 28 | - Android Version: [e.g. Nougat 7.1.2] 29 | - Specific to simulators: 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/usage-question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Usage Question 3 | about: Ask a question about AWS AppSync usage 4 | 5 | --- 6 | 7 | **State your question** 8 | 9 | **Provide code snippets (if applicable)** 10 | 11 | **Environment(please complete the following information):** 12 | - AppSync SDK Version: [e.g. 2.6.25] 13 | 14 | **Device Information (please complete the following information):** 15 | - Device: [e.g. Pixel XL, Simulator] 16 | - Android Version: [e.g. Nougat 7.1.2] 17 | - Specific to simulators: 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | 6 | By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. 7 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | # Setting this to 100 years, because we do not want to automatically mark issues as stale 3 | daysUntilStale: 36500 4 | # Number of days of inactivity before a stale issue is closed 5 | daysUntilClose: 7 6 | # Label to use when marking an issue as stale 7 | staleLabel: closing-soon-if-no-response 8 | # Comment to post when marking an issue as stale. Set to `false` to disable 9 | markComment: > 10 | This issue has been automatically marked as stale because it has not had 11 | recent activity. It will be closed if no further activity occurs. Thank you 12 | for your contributions. 13 | # Comment to post when closing a stale issue. Set to `false` to disable 14 | closeComment: > 15 | This issue has been automatically closed because of inactivity. 16 | Please open a new issue if are still encountering problems. 17 | # Limit to only `issues` or `pulls` 18 | only: issues 19 | -------------------------------------------------------------------------------- /.github/workflows/notify_comments.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: Notify Comments on Issues 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on comment events on pending response issues 8 | issue_comment: 9 | types: [created] 10 | 11 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 12 | jobs: 13 | # This workflow contains a single job called "notify" 14 | notify: 15 | # The type of runner that the job will run on 16 | runs-on: ubuntu-latest 17 | 18 | # Steps represent a sequence of tasks that will be executed as part of the job 19 | steps: 20 | # Runs a single command using the runners shell 21 | - name: Run webhook curl command 22 | env: 23 | WEBHOOK_URL: ${{ secrets.SLACK_COMMENT_WEBHOOK_URL }} 24 | BODY: ${{ toJson(github.event.comment.body) }} 25 | HTML_URL: ${{github.event.comment.html_url}} 26 | shell: bash 27 | run: echo "$BODY" | xargs -I {} curl -s POST "$WEBHOOK_URL" -H "Content-Type:application/json" --data '{"issue":"'"$HTML_URL"'", "body":"{}"}' 28 | -------------------------------------------------------------------------------- /.github/workflows/release_pr.yml: -------------------------------------------------------------------------------- 1 | name: Prepare Next Release 2 | on: 3 | workflow_dispatch: 4 | env: 5 | GIT_USER_NAME: awsmobilesdk-dev+ghops 6 | GIT_USER_EMAIL: awsmobilesdk-dev+ghops@amazon.com 7 | BASE_BRANCH: main 8 | jobs: 9 | create_pr_for_next_release: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Update git 13 | run: | 14 | sudo add-apt-repository -y ppa:git-core/ppa 15 | sudo apt-get update 16 | sudo apt-get install git -y 17 | - uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2 18 | with: 19 | ref: ${{ env.BASE_BRANCH }} 20 | fetch-depth: 0 21 | - name: Set up Ruby 22 | uses: ruby/setup-ruby@8575951200e472d5f2d95c625da0c7bec8217c42 # v1 23 | with: 24 | ruby-version: "3.0" 25 | - name: Install dependencies 26 | run: | 27 | cd build-support 28 | gem install bundler 29 | bundle install 30 | - name: Configure git options 31 | run: | 32 | cd build-support 33 | bundle exec fastlane android configure_git_options git_user_email:$GIT_USER_EMAIL git_user_name:$GIT_USER_NAME 34 | - name: Create/checkout a branch for the release 35 | run: | 36 | branch_name=bump_version 37 | git fetch --all 38 | (git branch -D $branch_name &>/dev/null) && (echo 'Existing $branch_name branch deleted') || (echo 'No existing $branch_name branch to delete.') 39 | git checkout -b $branch_name 40 | - name: Create PR for next release 41 | env: 42 | RELEASE_MANAGER_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | run: | 44 | cd build-support 45 | bundle exec fastlane android create_next_release_pr 46 | - name: Check modified file content 47 | run: | 48 | cat gradle.properties 49 | cat CHANGELOG.md 50 | git status 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # IntelliJ 38 | *.iml 39 | .idea/workspace.xml 40 | .idea/tasks.xml 41 | .idea/gradle.xml 42 | .idea/assetWizardSettings.xml 43 | .idea/dictionaries 44 | .idea/libraries 45 | .idea/caches 46 | 47 | # Keystore files 48 | # Uncomment the following line if you do not want to check your keystore files in. 49 | #*.jks 50 | 51 | # External native build folder generated in Android Studio 2.2 and later 52 | .externalNativeBuild 53 | 54 | # Google Services (e.g. APIs or Firebase) 55 | google-services.json 56 | 57 | # Freeline 58 | freeline.py 59 | freeline/ 60 | freeline_project_description.json 61 | 62 | # fastlane 63 | fastlane/report.xml 64 | fastlane/Preview.html 65 | fastlane/screenshots 66 | fastlane/test_output 67 | fastlane/readme.md 68 | 69 | # idea folder for tests 70 | aws-android-sdk-appsync-tests/.idea/ 71 | .idea/ 72 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | before_install: 2 | - openssl aes-256-cbc -K $encrypted_3a6b03bad5d0_key -iv $encrypted_3a6b03bad5d0_iv -in aws-android-sdk-appsync-tests/src/main/assets/awsconfiguration.json.enc -out aws-android-sdk-appsync-tests/src/main/res/raw/awsconfiguration.json -d 3 | - ls -l aws-android-sdk-appsync-tests/src/main/res/raw/awsconfiguration.json 4 | - wc aws-android-sdk-appsync-tests/src/main/res/raw/awsconfiguration.json 5 | - chmod +x gradlew 6 | - yes | sdkmanager "platforms;android-27" 7 | - android list target 8 | - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a 9 | - emulator -avd test -no-skin -no-audio -no-window & 10 | - android-wait-for-emulator 11 | - adb shell input keyevent 82 & 12 | language: android 13 | android: 14 | components: 15 | - tools 16 | - platform-tools 17 | - tools 18 | - build-tools-28.0.2 19 | - android-28 20 | - android-22 21 | - sys-img-armeabi-v7a-android-22 22 | script: 23 | - ./gradlew publishToMavenLocal 24 | - cd aws-android-sdk-appsync-tests 25 | - android list target 26 | - ./gradlew build connectedCheck --stacktrace 27 | - cd .. 28 | after_failure: 29 | - cat aws-android-sdk-appsync-tests/build/outputs/androidTest-results/connected/*.xml 30 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | App Sync SDK for Android 2 | Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | This product includes the Apollo GraphQL Client for Android library Copyright (c) 2016 Meteor Development Group, Inc., licensed under the MIT license. 5 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.amazonaws.appsync' 3 | 4 | android { 5 | compileSdkVersion 28 6 | 7 | defaultConfig { 8 | applicationId "com.amazonaws.mobileconnectors.appsync.demo" 9 | minSdkVersion 15 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | 22 | lintOptions { 23 | disable 'GradleDependency', 'GoogleAppIndexingWarning' 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation 'androidx.appcompat:appcompat:1.0.0' 29 | implementation 'androidx.core:core:1.0.0' 30 | implementation 'androidx.recyclerview:recyclerview:1.0.0' 31 | implementation 'com.google.android.material:material:1.0.0' 32 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 33 | implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' 34 | 35 | implementation project(':aws-android-sdk-appsync-runtime') 36 | implementation project(':aws-android-sdk-appsync-api') 37 | implementation project(':aws-android-sdk-appsync') 38 | 39 | implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.2' 40 | implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1' 41 | implementation "com.amazonaws:aws-android-sdk-core:$aws_version" 42 | implementation "com.amazonaws:aws-android-sdk-s3:$aws_version" 43 | 44 | def lifecycle_version = "2.0.0" 45 | implementation("androidx.lifecycle:lifecycle-runtime:$lifecycle_version") 46 | implementation("androidx.lifecycle:lifecycle-extensions:$lifecycle_version") 47 | } 48 | 49 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 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 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/graphql/com/amazonaws/amplify/generated/graphql/mutations.graphql: -------------------------------------------------------------------------------- 1 | # this is an auto generated file. This will be overwritten 2 | mutation CreatePost($input: CreatePostInput!) { 3 | createPost(input: $input) { 4 | id 5 | author 6 | title 7 | content 8 | url 9 | ups 10 | downs 11 | createdDate 12 | aws_ds 13 | } 14 | } 15 | mutation UpdatePost($input: UpdatePostInput!) { 16 | updatePost(input: $input) { 17 | id 18 | author 19 | title 20 | content 21 | url 22 | ups 23 | downs 24 | createdDate 25 | aws_ds 26 | } 27 | } 28 | mutation DeletePost($id: ID!) { 29 | deletePost(id: $id) { 30 | id 31 | author 32 | title 33 | content 34 | url 35 | ups 36 | downs 37 | createdDate 38 | aws_ds 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/graphql/com/amazonaws/amplify/generated/graphql/queries.graphql: -------------------------------------------------------------------------------- 1 | # this is an auto generated file. This will be overwritten 2 | query GetPost($id: ID!) { 3 | getPost(id: $id) { 4 | id 5 | author 6 | title 7 | content 8 | url 9 | ups 10 | downs 11 | createdDate 12 | aws_ds 13 | } 14 | } 15 | query ListPosts { 16 | listPosts { 17 | id 18 | author 19 | title 20 | content 21 | url 22 | ups 23 | downs 24 | createdDate 25 | aws_ds 26 | } 27 | } 28 | query ListPostsDelta($lastSync: AWSTimestamp) { 29 | listPostsDelta(lastSync: $lastSync) { 30 | id 31 | author 32 | title 33 | content 34 | url 35 | ups 36 | downs 37 | createdDate 38 | aws_ds 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/graphql/com/amazonaws/amplify/generated/graphql/subscriptions.graphql: -------------------------------------------------------------------------------- 1 | # this is an auto generated file. This will be overwritten 2 | subscription OnDeltaPost { 3 | onDeltaPost { 4 | id 5 | author 6 | title 7 | content 8 | url 9 | ups 10 | downs 11 | createdDate 12 | aws_ds 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/amazonaws/postsapp/ClientFactory.java: -------------------------------------------------------------------------------- 1 | package com.amazonaws.postsapp; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.util.Log; 6 | 7 | import com.amazonaws.auth.AWSCredentialsProvider; 8 | import com.amazonaws.auth.CognitoCachingCredentialsProvider; 9 | import com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient; 10 | import com.amazonaws.mobileconnectors.appsync.PersistentMutationsCallback; 11 | import com.amazonaws.mobileconnectors.appsync.PersistentMutationsError; 12 | import com.amazonaws.mobileconnectors.appsync.PersistentMutationsResponse; 13 | import com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider; 14 | 15 | 16 | public class ClientFactory { 17 | private static volatile AWSAppSyncClient client; 18 | 19 | public synchronized static AWSAppSyncClient getInstance(Context context) { 20 | if (client == null) { 21 | client = AWSAppSyncClient.builder() 22 | .context(context) 23 | .apiKey(new BasicAPIKeyAuthProvider(Constants.APPSYNC_API_KEY)) // For use with IAM/Cognito authorization 24 | .region(Constants.APPSYNC_REGION) 25 | .serverUrl(Constants.APPSYNC_API_URL) 26 | .persistentMutationsCallback(new PersistentMutationsCallback() { 27 | @Override 28 | public void onResponse(PersistentMutationsResponse response) { 29 | Log.d("NOTERROR", response.getMutationClassName()); 30 | } 31 | 32 | @Override 33 | public void onFailure(PersistentMutationsError error) { 34 | Log.e("TAG", error.getMutationClassName()); 35 | Log.e("TAG", "Error", error.getException()); 36 | } 37 | }) 38 | .build(); 39 | } 40 | return client; 41 | } 42 | } -------------------------------------------------------------------------------- /app/src/main/java/com/amazonaws/postsapp/Constants.java: -------------------------------------------------------------------------------- 1 | package com.amazonaws.postsapp; 2 | 3 | import com.amazonaws.regions.Regions; 4 | 5 | public class Constants { 6 | public static final Regions APPSYNC_REGION = Regions.US_EAST_1; // TODO: Update the region to match the API region 7 | public static final String APPSYNC_API_URL = ""; // TODO: Update the endpoint URL as specified on AppSync console 8 | 9 | // API Key Authorization 10 | public static final String APPSYNC_API_KEY = "API-KEY"; // TODO: Copy the API Key specified on the AppSync Console 11 | 12 | // IAM based Authorization (Cognito Identity) 13 | public static final String COGNITO_IDENTITY = ""; // TODO: Update the Cognito Identity Pool ID 14 | public static final Regions COGNITO_REGION = Regions.US_EAST_1; // TODO: Update the region to match the Cognito Identity Pool region 15 | 16 | // Cognito User Pools Authorization 17 | public static final String USER_POOLS_POOL_ID = ""; 18 | public static final String USER_POOLS_CLIENT_ID = ""; 19 | public static final String USER_POOLS_CLIENT_SECRET = ""; 20 | public static final Regions USER_POOLS_REGION = Regions.US_WEST_2; // TODO: Update the region to match the Cognito User Pools region 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/amazonaws/postsapp/UpdatePostActivity.java: -------------------------------------------------------------------------------- 1 | package com.amazonaws.postsapp; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import androidx.appcompat.app.AppCompatActivity; 7 | 8 | import android.view.Menu; 9 | import android.view.MenuItem; 10 | import android.widget.EditText; 11 | 12 | 13 | import com.amazonaws.amplify.generated.graphql.ListPostsQuery; 14 | 15 | public class UpdatePostActivity extends AppCompatActivity { 16 | private static ListPostsQuery.ListPost sPost; 17 | private static int sPosition; 18 | 19 | public static void startActivity(Context context, ListPostsQuery.ListPost post, int position) { 20 | Intent updatePostIntent = new Intent(context, UpdatePostActivity.class); 21 | sPost = post; 22 | sPosition = position; 23 | context.startActivity(updatePostIntent); 24 | } 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_update_post); 30 | 31 | ((EditText) findViewById(R.id.updateTitle)).setText(sPost.title()); 32 | ((EditText) findViewById(R.id.updateAuthor)).setText(sPost.author()); 33 | ((EditText) findViewById(R.id.updateContent)).setText(sPost.content()); 34 | } 35 | 36 | @Override 37 | public boolean onCreateOptionsMenu(Menu menu) { 38 | // Inflate the menu; this adds items to the action bar if it is present. 39 | getMenuInflater().inflate(R.menu.menu_save, menu); 40 | return true; 41 | } 42 | 43 | @Override 44 | public boolean onOptionsItemSelected(MenuItem item) { 45 | int id = item.getItemId(); 46 | 47 | if (id == R.id.action_save) { 48 | save(); 49 | return true; 50 | } 51 | 52 | return super.onOptionsItemSelected(item); 53 | } 54 | 55 | private void save() { 56 | // TODO: Here for update post mutation 57 | } 58 | // TODO: Here for update post callback 59 | 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_add_post.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 20 | 21 | 26 | 30 | 31 | 36 | 40 | 41 | 46 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_posts.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 20 | 21 | 22 | 23 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_update_post.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 20 | 21 | 26 | 30 | 31 | 36 | 40 | 41 | 46 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/res/layout/post.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 22 | 27 | 31 | 38 | 45 | 53 | 54 | 55 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_save.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PostsApp 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | apply plugin: 'maven-publish' 3 | 4 | apply from: rootProject.file('gradle-mvn-push.gradle') 5 | 6 | dependencies { 7 | implementation fileTree(dir: 'libs', include: ['*.jar']) 8 | implementation 'com.google.code.findbugs:jsr305:3.0.2' // compileOnly 9 | api 'javax.annotation:jsr250-api:1.0' // compileOnly 10 | 11 | implementation 'com.squareup.okhttp3:okhttp:4.3.1' // compileOnly 12 | } 13 | 14 | publishing { 15 | publications { 16 | pluginPublication(MavenPublication) { 17 | from components.java 18 | groupId 'com.amazonaws' 19 | artifactId 'aws-android-sdk-appsync-api' 20 | version VERSION_NAME + "-SNAPSHOT" 21 | } 22 | } 23 | } 24 | 25 | sourceCompatibility = "1.7" 26 | targetCompatibility = "1.7" 27 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=aws-android-sdk-appsync-api 2 | POM_NAME=AWS SDK for Android GraphQL API 3 | POM_DESCRIPTION=AWS SDK for Android GraphQL API classes 4 | POM_PACKAGING=jar 5 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/Logger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo; 9 | 10 | import com.apollographql.apollo.api.internal.Optional; 11 | 12 | import javax.annotation.Nonnull; 13 | 14 | /** 15 | * Logger to use for logging 16 | */ 17 | public interface Logger { 18 | int DEBUG = 3; 19 | int WARN = 5; 20 | int ERROR = 6; 21 | 22 | /** 23 | * Logs the message to the appropriate channel (file, console, etc) 24 | * 25 | * @param priority the priority to set 26 | * @param message message to log 27 | * @param t Optional throwable to log 28 | * @param args extra arguments to pass to the logged message. 29 | */ 30 | void log(int priority, @Nonnull String message, @Nonnull Optional t, @Nonnull Object... args); 31 | } 32 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/FragmentResponseFieldMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * FragmentResponseFieldMapper is responsible for mapping the response back to a fragment of type T. 14 | */ 15 | public interface FragmentResponseFieldMapper { 16 | T map(final ResponseReader responseReader, String conditionalType) throws IOException; 17 | } 18 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/GraphqlFragment.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | /** 11 | * Represents a GraphQL fragment 12 | */ 13 | public interface GraphqlFragment { 14 | 15 | /** 16 | * Returns marshaller to serialize fragment data 17 | * 18 | * @return {@link ResponseFieldMarshaller} to serialize fragment data 19 | */ 20 | ResponseFieldMarshaller marshaller(); 21 | } 22 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/Input.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | import javax.annotation.Nullable; 11 | 12 | public final class Input { 13 | public final V value; 14 | public final boolean defined; 15 | 16 | private Input(V value, boolean defined) { 17 | this.value = value; 18 | this.defined = defined; 19 | } 20 | 21 | public static Input fromNullable(@Nullable V value) { 22 | return new Input<>(value, true); 23 | } 24 | 25 | public static Input absent() { 26 | return new Input<>(null, false); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/InputFieldMarshaller.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | import java.io.IOException; 11 | 12 | public interface InputFieldMarshaller { 13 | void marshal(InputFieldWriter writer) throws IOException; 14 | } 15 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/InputFieldWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | import java.io.IOException; 11 | 12 | import javax.annotation.Nonnull; 13 | 14 | public interface InputFieldWriter { 15 | void writeString(@Nonnull String fieldName, String value) throws IOException; 16 | 17 | void writeInt(@Nonnull String fieldName, Integer value) throws IOException; 18 | 19 | void writeLong(@Nonnull String fieldName, Long value) throws IOException; 20 | 21 | void writeDouble(@Nonnull String fieldName, Double value) throws IOException; 22 | 23 | void writeBoolean(@Nonnull String fieldName, Boolean value) throws IOException; 24 | 25 | void writeCustom(@Nonnull String fieldName, ScalarType scalarType, Object value) throws IOException; 26 | 27 | void writeObject(@Nonnull String fieldName, InputFieldMarshaller marshaller) throws IOException; 28 | 29 | void writeList(@Nonnull String fieldName, ListWriter listWriter) throws IOException; 30 | 31 | interface ListWriter { 32 | void write(@Nonnull ListItemWriter listItemWriter) throws IOException; 33 | } 34 | 35 | interface ListItemWriter { 36 | void writeString(String value) throws IOException; 37 | 38 | void writeInt(Integer value) throws IOException; 39 | 40 | void writeLong(Long value) throws IOException; 41 | 42 | void writeDouble(Double value) throws IOException; 43 | 44 | void writeBoolean(Boolean value) throws IOException; 45 | 46 | void writeCustom(ScalarType scalarType, Object value) throws IOException; 47 | 48 | void writeObject(InputFieldMarshaller marshaller) throws IOException; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/InputType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | import javax.annotation.Nonnull; 11 | 12 | public interface InputType { 13 | @Nonnull InputFieldMarshaller marshaller(); 14 | } 15 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/Mutation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | /** 11 | * Represents a GraphQL mutation operation that will be sent to the server. 12 | */ 13 | public interface Mutation extends Operation { 14 | } 15 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/OperationName.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | /** 11 | * GraphQL operation name. 12 | */ 13 | public interface OperationName { 14 | /** 15 | * Returns operation name. 16 | * 17 | * @return operation name 18 | */ 19 | String name(); 20 | } 21 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/Query.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | /** 11 | * Represents a GraphQL query that will be sent to the server. 12 | */ 13 | public interface Query extends Operation { 14 | } 15 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/ResponseFieldMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | /** 11 | * ResponseFieldMapper is an abstraction for mapping the response data returned by 12 | * the server back to generated models. 13 | */ 14 | public interface ResponseFieldMapper { 15 | T map(final ResponseReader responseReader); 16 | } 17 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/ResponseFieldMarshaller.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | public interface ResponseFieldMarshaller { 11 | void marshal(ResponseWriter writer); 12 | } 13 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/ResponseReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | import java.util.List; 11 | 12 | /* 13 | * ResponseReader is an abstraction for reading GraphQL fields. 14 | */ 15 | public interface ResponseReader { 16 | 17 | String readString(ResponseField field); 18 | 19 | Integer readInt(ResponseField field); 20 | 21 | Long readLong(ResponseField field); 22 | 23 | Double readDouble(ResponseField field); 24 | 25 | Boolean readBoolean(ResponseField field); 26 | 27 | T readObject(ResponseField field, ObjectReader objectReader); 28 | 29 | List readList(ResponseField field, ListReader listReader); 30 | 31 | T readCustomType(ResponseField.CustomTypeField field); 32 | 33 | T readConditional(ResponseField field, ConditionalTypeReader conditionalTypeReader); 34 | 35 | interface ObjectReader { 36 | T read(ResponseReader reader); 37 | } 38 | 39 | interface ListReader { 40 | T read(ListItemReader reader); 41 | } 42 | 43 | interface ConditionalTypeReader { 44 | T read(String conditionalType, ResponseReader reader); 45 | } 46 | 47 | interface ListItemReader { 48 | 49 | String readString(); 50 | 51 | Integer readInt(); 52 | 53 | Long readLong(); 54 | 55 | Double readDouble(); 56 | 57 | Boolean readBoolean(); 58 | 59 | T readCustomType(ScalarType scalarType); 60 | 61 | T readObject(ObjectReader objectReader); 62 | 63 | List readList(ListReader listReader); 64 | } 65 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/ResponseWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | import java.util.List; 11 | 12 | import javax.annotation.Nonnull; 13 | import javax.annotation.Nullable; 14 | 15 | public interface ResponseWriter { 16 | void writeString(@Nonnull ResponseField field, @Nullable String value); 17 | 18 | void writeInt(@Nonnull ResponseField field, @Nullable Integer value); 19 | 20 | void writeLong(@Nonnull ResponseField field, @Nullable Long value); 21 | 22 | void writeDouble(@Nonnull ResponseField field, @Nullable Double value); 23 | 24 | void writeBoolean(@Nonnull ResponseField field, @Nullable Boolean value); 25 | 26 | void writeCustom(@Nonnull ResponseField.CustomTypeField field, @Nullable Object value); 27 | 28 | void writeObject(@Nonnull ResponseField field, @Nullable ResponseFieldMarshaller marshaller); 29 | 30 | void writeList(@Nonnull ResponseField field, @Nullable List values, @Nonnull ListWriter listWriter); 31 | 32 | interface ListWriter { 33 | void write(@Nullable Object value, @Nonnull ListItemWriter listItemWriter); 34 | } 35 | 36 | interface ListItemWriter { 37 | void writeString(@Nullable Object value); 38 | 39 | void writeInt(@Nullable Object value); 40 | 41 | void writeLong(@Nullable Object value); 42 | 43 | void writeDouble(@Nullable Object value); 44 | 45 | void writeBoolean(@Nullable Object value); 46 | 47 | void writeCustom(@Nonnull ScalarType scalarType, @Nullable Object value); 48 | 49 | void writeObject(@Nullable ResponseFieldMarshaller marshaller); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/S3InputObjectInterface.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | /** 11 | * S3InputObjectInterface. 12 | */ 13 | 14 | public interface S3InputObjectInterface extends S3ObjectInterface { 15 | public String localUri(); 16 | public String mimeType(); 17 | } 18 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/S3ObjectInterface.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | /** 11 | * S3ObjectInterface. 12 | */ 13 | 14 | public interface S3ObjectInterface { 15 | public String bucket(); 16 | public String key(); 17 | public String region(); 18 | } 19 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/S3ObjectManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | /** 11 | * S3ObjectManager. 12 | */ 13 | public interface S3ObjectManager { 14 | void upload(final S3InputObjectInterface s3Object) throws Exception; 15 | void download(final S3ObjectInterface s3Object, final String filePath) throws Exception; 16 | } 17 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/ScalarType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | /** 11 | * Represents a custom GraphQL scalar type 12 | */ 13 | public interface ScalarType { 14 | String typeName(); 15 | 16 | Class javaType(); 17 | } 18 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/Subscription.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api; 9 | 10 | /** 11 | * Represents a GraphQL subscription. 12 | */ 13 | public interface Subscription extends Operation { 14 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/cache/http/HttpCacheRecord.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api.cache.http; 9 | 10 | import javax.annotation.Nonnull; 11 | 12 | import okio.Source; 13 | 14 | public interface HttpCacheRecord { 15 | @Nonnull Source headerSource(); 16 | 17 | @Nonnull Source bodySource(); 18 | 19 | void close(); 20 | } 21 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/cache/http/HttpCacheRecordEditor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api.cache.http; 9 | 10 | import java.io.IOException; 11 | 12 | import javax.annotation.Nonnull; 13 | 14 | import okio.Sink; 15 | 16 | public interface HttpCacheRecordEditor { 17 | @Nonnull Sink headerSink(); 18 | 19 | @Nonnull Sink bodySink(); 20 | 21 | void abort() throws IOException; 22 | 23 | void commit() throws IOException; 24 | } 25 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/cache/http/HttpCacheStore.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api.cache.http; 9 | 10 | import java.io.IOException; 11 | 12 | import javax.annotation.Nonnull; 13 | import javax.annotation.Nullable; 14 | 15 | /** 16 | * CacheStore is an abstraction for a cache store that is used to read, modify or delete http responses. 17 | */ 18 | public interface HttpCacheStore { 19 | /** 20 | * Returns ResponseCacheRecord for the entry named cacheKey or null if it doesn't exist or is not currently readable. 21 | * 22 | * @param cacheKey the name of the entry 23 | * @return ResponseCacheRecord 24 | */ 25 | @Nullable HttpCacheRecord cacheRecord(@Nonnull String cacheKey) throws IOException; 26 | 27 | /** 28 | * Returns an editor for the entry named cacheKey or null if another edit is in progress. 29 | * 30 | * @param cacheKey the entry to edit. 31 | * @return {@link HttpCacheRecordEditor} to use for editing the entry 32 | */ 33 | @Nullable HttpCacheRecordEditor cacheRecordEditor(@Nonnull String cacheKey) throws IOException; 34 | 35 | /** 36 | * Drops the entry for key if it exists and can be removed. If the entry for key is currently being edited, that edit 37 | * will complete normally but its value will not be stored. 38 | */ 39 | void remove(@Nonnull String cacheKey) throws IOException; 40 | 41 | /** 42 | * Closes the cache and deletes all of its stored values. This will delete all files in the cache directory including 43 | * files that weren't created by the cache. 44 | */ 45 | void delete() throws IOException; 46 | } 47 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/internal/Action.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api.internal; 9 | 10 | import javax.annotation.Nonnull; 11 | 12 | public interface Action { 13 | void apply(@Nonnull T t); 14 | } 15 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/internal/Function.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api.internal; 9 | 10 | import javax.annotation.Nonnull; 11 | 12 | public interface Function { 13 | /** 14 | * Apply some calculation to the input value and return some other value. 15 | * 16 | * @param t the input value 17 | * @return the output value 18 | */ 19 | @Nonnull 20 | R apply(@Nonnull T t); 21 | } 22 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/internal/Functions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api.internal; 9 | 10 | 11 | import javax.annotation.Nullable; 12 | 13 | import static com.apollographql.apollo.api.internal.Utils.checkNotNull; 14 | 15 | public class Functions { 16 | /** 17 | * Returns the identity function. 18 | */ 19 | // implementation is "fully variant"; E has become a "pass-through" type 20 | public static Function identity() { 21 | return (Function) IdentityFunction.INSTANCE; 22 | } 23 | 24 | // enum singleton pattern 25 | private enum IdentityFunction implements Function { 26 | INSTANCE; 27 | 28 | @Override 29 | @Nullable 30 | public Object apply(@Nullable Object o) { 31 | return o; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Functions.identity()"; 37 | } 38 | } 39 | 40 | /** 41 | * Returns a function that calls {@code toString()} on its argument. The function does not accept 42 | * nulls; it will throw a {@link NullPointerException} when applied to {@code null}. 43 | * 44 | *

Warning: The returned function may not be consistent with equals (as 45 | * documented at {@link Function#apply}). For example, this function yields different results for 46 | * the two equal instances {@code ImmutableSet.of(1, 2)} and {@code ImmutableSet.of(2, 1)}. 47 | */ 48 | public static Function toStringFunction() { 49 | return ToStringFunction.INSTANCE; 50 | } 51 | 52 | // enum singleton pattern 53 | private enum ToStringFunction implements Function { 54 | INSTANCE; 55 | 56 | @Override 57 | public String apply(Object o) { 58 | checkNotNull(o); // eager for GWT. 59 | return o.toString(); 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return "Functions.toStringFunction()"; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/internal/Mutator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api.internal; 9 | 10 | /** 11 | * Represents an operation that accepts a single input argument, mutate it and returns no result 12 | * 13 | * @param the type of the input to the operation 14 | */ 15 | public interface Mutator { 16 | 17 | /** 18 | * Performs this operation on the given argument. 19 | * 20 | * @param t the input argument 21 | */ 22 | void accept(T t); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/api/internal/UnmodifiableMapBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.api.internal; 9 | 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public class UnmodifiableMapBuilder { 15 | 16 | private final Map map; 17 | 18 | public UnmodifiableMapBuilder(int initialCapacity) { 19 | this.map = new HashMap<>(initialCapacity); 20 | } 21 | 22 | public UnmodifiableMapBuilder() { 23 | this.map = new HashMap<>(); 24 | } 25 | 26 | public UnmodifiableMapBuilder put(K key, V value) { 27 | map.put(key, value); 28 | return this; 29 | } 30 | 31 | public Map build() { 32 | return Collections.unmodifiableMap(map); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-api/src/main/java/com/apollographql/apollo/internal/ApolloLogger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal; 9 | 10 | import com.apollographql.apollo.Logger; 11 | import com.apollographql.apollo.api.internal.Optional; 12 | 13 | import javax.annotation.Nonnull; 14 | import javax.annotation.Nullable; 15 | 16 | import static com.apollographql.apollo.api.internal.Utils.checkNotNull; 17 | 18 | public final class ApolloLogger { 19 | 20 | private final Optional logger; 21 | 22 | public ApolloLogger(@Nonnull Optional logger) { 23 | this.logger = checkNotNull(logger, "logger == null"); 24 | } 25 | 26 | public void d(@Nonnull String message, Object... args) { 27 | log(Logger.DEBUG, message, null, args); 28 | } 29 | 30 | public void d(@Nullable Throwable t, @Nonnull String message, Object... args) { 31 | log(Logger.DEBUG, message, t, args); 32 | } 33 | 34 | public void w(@Nonnull String message, Object... args) { 35 | log(Logger.WARN, message, null, args); 36 | } 37 | 38 | public void w(@Nullable Throwable t, @Nonnull String message, Object... args) { 39 | log(Logger.WARN, message, t, args); 40 | } 41 | 42 | public void e(@Nonnull String message, Object... args) { 43 | log(Logger.ERROR, message, null, args); 44 | } 45 | 46 | public void e(@Nullable Throwable t, @Nonnull String message, Object... args) { 47 | log(Logger.ERROR, message, t, args); 48 | } 49 | 50 | private void log(int priority, @Nonnull String message, @Nullable Throwable t, Object... args) { 51 | if (logger.isPresent()) { 52 | logger.get().log(priority, message, Optional.fromNullable(t), args); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | apply plugin: 'kotlin' 3 | apply plugin: 'maven-publish' 4 | 5 | apply from: rootProject.file('gradle-mvn-push.gradle') 6 | 7 | sourceSets { 8 | main.java.srcDir "src/main/build" 9 | main.java.srcDir "src/generated/kotlin" 10 | } 11 | 12 | dependencies { 13 | implementation fileTree(dir: 'libs', include: ['*.jar']) 14 | 15 | implementation 'com.squareup:javapoet:1.8.0' // impl 16 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // impl 17 | implementation 'com.squareup.moshi:moshi:1.5.0' // impl 18 | implementation 'com.google.code.findbugs:jsr305:3.0.2' // compileOnly 19 | 20 | implementation project(':aws-android-sdk-appsync-api') // impl 21 | } 22 | 23 | publishing { 24 | publications { 25 | pluginPublication(MavenPublication) { 26 | from components.java 27 | groupId 'com.amazonaws' 28 | artifactId 'aws-android-sdk-appsync-compiler' 29 | version VERSION_NAME + "-SNAPSHOT" 30 | } 31 | } 32 | } 33 | 34 | task pluginVersion { 35 | def outputDir = file("src/generated/kotlin") 36 | 37 | doLast { 38 | def versionFile = file("$outputDir/com/apollographql/android/Version.kt") 39 | versionFile.parentFile.mkdirs() 40 | versionFile.text = """// Generated file. Do not edit! 41 | package com.apollographql.android 42 | val VERSION = "$VERSION_NAME" 43 | """ 44 | } 45 | } 46 | 47 | tasks.getByName('compileKotlin').dependsOn('pluginVersion') 48 | 49 | sourceCompatibility = "1.7" 50 | targetCompatibility = "1.7" 51 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=aws-android-sdk-appsync-compiler 2 | POM_NAME=AWS SDK for Android - Android Compiler 3 | POM_DESCRIPTION=AWS AppSync Implementation for the Gradle plugin 4 | POM_PACKAGING=jar -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/generated/kotlin/com/apollographql/android/Version.kt: -------------------------------------------------------------------------------- 1 | // Generated file. Do not edit! 2 | package com.apollographql.android 3 | val VERSION = "3.1.3" 4 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/Annotations.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler 9 | 10 | import com.squareup.javapoet.AnnotationSpec 11 | import com.squareup.javapoet.CodeBlock 12 | import javax.annotation.Generated 13 | import javax.annotation.Nonnull 14 | import javax.annotation.Nullable 15 | 16 | object Annotations { 17 | val NULLABLE: AnnotationSpec = AnnotationSpec.builder(Nullable::class.java).build() 18 | val NONNULL: AnnotationSpec = AnnotationSpec.builder(Nonnull::class.java).build() 19 | val OVERRIDE: AnnotationSpec = AnnotationSpec.builder(Override::class.java).build() 20 | val GENERATED_BY_APOLLO: AnnotationSpec = AnnotationSpec.builder(Generated::class.java) 21 | .addMember("value", CodeBlock.of("\$S", "Apollo GraphQL")).build() 22 | val DEPRECATED: AnnotationSpec = AnnotationSpec.builder(java.lang.Deprecated::class.java).build() 23 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/CustomEnumTypeSpecBuilder.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler 9 | 10 | import com.apollographql.apollo.api.ScalarType 11 | import com.apollographql.apollo.compiler.ir.CodeGenerationContext 12 | import com.squareup.javapoet.ClassName 13 | import com.squareup.javapoet.MethodSpec 14 | import com.squareup.javapoet.TypeSpec 15 | import java.util.* 16 | import javax.lang.model.element.Modifier 17 | 18 | class CustomEnumTypeSpecBuilder( 19 | val context: CodeGenerationContext 20 | ) { 21 | fun build(): TypeSpec = 22 | TypeSpec.enumBuilder(className(context)) 23 | .addAnnotation(Annotations.GENERATED_BY_APOLLO) 24 | .addSuperinterface(ScalarType::class.java) 25 | .addModifiers(Modifier.PUBLIC) 26 | .addEnumConstants() 27 | .build() 28 | 29 | private fun TypeSpec.Builder.addEnumConstants(): TypeSpec.Builder { 30 | context.customTypeMap.forEach { mapping -> 31 | val constantName = mapping.key.removeSuffix("!").toUpperCase(Locale.ENGLISH) 32 | val javaTypeName = mapping.value 33 | addEnumConstant(constantName, scalarMappingTypeSpec(mapping.key, javaTypeName)) 34 | } 35 | return this 36 | } 37 | 38 | private fun scalarMappingTypeSpec(scalarType: String, javaTypeName: String) = 39 | TypeSpec.anonymousClassBuilder("") 40 | .addMethod(MethodSpec.methodBuilder("typeName") 41 | .addModifiers(Modifier.PUBLIC) 42 | .addAnnotation(Override::class.java) 43 | .returns(java.lang.String::class.java) 44 | .addStatement("return \$S", scalarType) 45 | .build()) 46 | .addMethod(MethodSpec.methodBuilder("javaType") 47 | .addModifiers(Modifier.PUBLIC) 48 | .addAnnotation(Override::class.java) 49 | .returns(Class::class.java) 50 | .addStatement("return \$T.class", javaTypeName.toJavaType()) 51 | .build()) 52 | .build() 53 | 54 | companion object { 55 | fun className(context: CodeGenerationContext): ClassName = ClassName.get(context.typesPackage, "CustomType") 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/NullableValueType.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler 9 | 10 | enum class NullableValueType(val value: String) { 11 | ANNOTATED("annotated"), 12 | APOLLO_OPTIONAL("apolloOptional"), 13 | GUAVA_OPTIONAL("guavaOptional"), 14 | JAVA_OPTIONAL("javaOptional"), 15 | INPUT_TYPE("inputType"); 16 | 17 | companion object { 18 | fun findByValue(value: String): NullableValueType? = NullableValueType.values().find { it.value == value } 19 | } 20 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/CodeGenerationContext.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler.ir 9 | 10 | import com.apollographql.apollo.compiler.NullableValueType 11 | 12 | data class CodeGenerationContext( 13 | var reservedTypeNames: List, 14 | val typeDeclarations: List, 15 | val fragmentsPackage: String = "", 16 | val typesPackage: String = "", 17 | val customTypeMap: Map, 18 | val nullableValueType: NullableValueType, 19 | val generateAccessors: Boolean, 20 | val ir: CodeGenerationIR, 21 | val useSemanticNaming: Boolean, 22 | val generateModelBuilder: Boolean 23 | ) -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/CodeGenerationIR.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler.ir 9 | 10 | data class CodeGenerationIR( 11 | val operations: List, 12 | val fragments: List, 13 | val typesUsed: List 14 | ) 15 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/CodeGenerator.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler.ir 9 | 10 | import com.squareup.javapoet.TypeSpec 11 | 12 | interface CodeGenerator { 13 | fun toTypeSpec(context: CodeGenerationContext): TypeSpec 14 | } 15 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/Condition.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler.ir 9 | 10 | data class Condition( 11 | val kind: String, 12 | val variableName: String, 13 | val inverted: Boolean 14 | ) { 15 | 16 | enum class Kind(val rawValue: String) { 17 | BOOLEAN("BooleanCondition") 18 | } 19 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/InlineFragment.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler.ir 9 | 10 | import com.apollographql.apollo.compiler.JavaTypeResolver 11 | import com.apollographql.apollo.compiler.SchemaTypeSpecBuilder 12 | import com.apollographql.apollo.compiler.withBuilder 13 | import com.squareup.javapoet.FieldSpec 14 | import com.squareup.javapoet.MethodSpec 15 | import com.squareup.javapoet.TypeSpec 16 | import javax.lang.model.element.Modifier 17 | 18 | data class InlineFragment( 19 | val typeCondition: String, 20 | val possibleTypes: List?, 21 | val fields: List, 22 | val fragmentSpreads: List? 23 | ) : CodeGenerator { 24 | override fun toTypeSpec(context: CodeGenerationContext): TypeSpec = 25 | SchemaTypeSpecBuilder( 26 | typeName = formatClassName(), 27 | fields = fields, 28 | fragmentSpreads = fragmentSpreads ?: emptyList(), 29 | inlineFragments = emptyList(), 30 | context = context 31 | ) 32 | .build(Modifier.PUBLIC, Modifier.STATIC) 33 | .let { 34 | if (context.generateModelBuilder) { 35 | it.withBuilder() 36 | } else { 37 | it 38 | } 39 | } 40 | 41 | fun accessorMethodSpec(context: CodeGenerationContext): MethodSpec { 42 | return MethodSpec.methodBuilder(formatClassName().decapitalize()) 43 | .addModifiers(Modifier.PUBLIC) 44 | .returns(typeName(context)) 45 | .addStatement("return this.\$L", formatClassName().decapitalize()) 46 | .build() 47 | } 48 | 49 | fun fieldSpec(context: CodeGenerationContext, publicModifier: Boolean = false): FieldSpec = 50 | FieldSpec.builder(typeName(context), formatClassName().decapitalize()) 51 | .let { if (publicModifier) it.addModifiers(Modifier.PUBLIC) else it } 52 | .addModifiers(Modifier.FINAL) 53 | .build() 54 | 55 | fun formatClassName(): String = "$INTERFACE_PREFIX${typeCondition.capitalize()}" 56 | 57 | private fun typeName(context: CodeGenerationContext) = JavaTypeResolver(context, "").resolve(formatClassName(), true) 58 | 59 | companion object { 60 | private val INTERFACE_PREFIX = "As" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/ScalarType.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler.ir 9 | 10 | sealed class ScalarType(val name: String) { 11 | object ID : ScalarType("ID") 12 | object STRING : ScalarType("String") 13 | object INT : ScalarType("Int") 14 | object BOOLEAN : ScalarType("Boolean") 15 | object FLOAT : ScalarType("Float") 16 | object AWS_TIMESTAMP : ScalarType("AWSTimestamp") 17 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/TypeDeclarationField.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler.ir 9 | 10 | data class TypeDeclarationField( 11 | val name: String, 12 | val description: String, 13 | val type: String, 14 | val defaultValue: Any? 15 | ) -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/TypeDeclarationValue.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler.ir 9 | 10 | data class TypeDeclarationValue( 11 | val name: String, 12 | val description: String?, 13 | val isDeprecated: Boolean? = false, 14 | val deprecationReason: String? = null 15 | ) -------------------------------------------------------------------------------- /aws-android-sdk-appsync-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ir/Variable.kt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.compiler.ir 9 | 10 | data class Variable( 11 | val name: String, 12 | val type: String 13 | ) { 14 | fun optional(): Boolean = !type.endsWith(suffix = "!") 15 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync-gradle-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-gradle-plugin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'idea' 3 | apply plugin: 'java-gradle-plugin' 4 | apply plugin: 'maven-publish' 5 | 6 | apply from: rootProject.file('gradle-mvn-push.gradle') 7 | 8 | sourceSets.main.java.srcDirs = [] 9 | sourceSets.main.groovy.srcDirs = ["src/main/java", "src/main/groovy"] 10 | 11 | dependencies { 12 | implementation fileTree(dir: 'libs', include: ['*.jar']) 13 | 14 | compileOnly gradleApi() 15 | compileOnly localGroovy() 16 | implementation 'com.github.node-gradle:gradle-node-plugin:2.2.4' 17 | implementation 'com.android.tools.build:gradle:3.5.3' // compileOnly 18 | implementation 'com.squareup.moshi:moshi:1.5.0' // impl 19 | 20 | implementation project(':aws-android-sdk-appsync-compiler') // impl 21 | } 22 | 23 | publishing { 24 | publications { 25 | pluginPublication(MavenPublication) { 26 | from components.java 27 | groupId 'com.amazonaws' 28 | artifactId 'aws-android-sdk-appsync-gradle-plugin' 29 | version VERSION_NAME + "-SNAPSHOT" 30 | } 31 | } 32 | } 33 | 34 | sourceCompatibility = "1.7" 35 | targetCompatibility = "1.7" 36 | 37 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-gradle-plugin/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=aws-android-sdk-appsync-gradle-plugin 2 | POM_NAME=AWS SDK for Android - Gradle Plugin 3 | POM_DESCRIPTION=Gradle plugin for generating java classes for graphql files 4 | POM_PACKAGING=jar 5 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-gradle-plugin/src/main/java/com/apollographql/apollo/gradle/ApolloCodegenArgs.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.gradle; 9 | 10 | import java.io.File; 11 | import java.util.Set; 12 | 13 | final class ApolloCodegenArgs { 14 | final File schemaFile; 15 | final Set queryFilePaths; 16 | final File irOutputFolder; 17 | 18 | ApolloCodegenArgs(File schemaFile, Set queryFilePaths, File irOutputFolder) { 19 | this.schemaFile = schemaFile; 20 | this.queryFilePaths = queryFilePaths; 21 | this.irOutputFolder = irOutputFolder; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-gradle-plugin/src/main/java/com/apollographql/apollo/gradle/Utils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.gradle; 9 | 10 | import java.io.File; 11 | 12 | public class Utils { 13 | static String capitalize(String s) { 14 | return s.substring(0, 1).toUpperCase() + s.substring(1); 15 | } 16 | 17 | static boolean isNullOrEmpty(String s) { 18 | return s == null || s.length() == 0; 19 | } 20 | 21 | static void deleteDirectory(File directory) { 22 | if (directory.exists()){ 23 | File[] files = directory.listFiles(); 24 | if (files != null){ 25 | for (File file : files) { 26 | if (file.isDirectory()) { 27 | deleteDirectory(file); 28 | } else { 29 | file.delete(); 30 | } 31 | } 32 | } 33 | } 34 | directory.delete(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-gradle-plugin/src/main/resources/META-INF/gradle-plugins/com.amazonaws.appsync.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.apollographql.apollo.gradle.ApolloPlugin -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | apply plugin: 'maven-publish' 3 | apply from: rootProject.file('gradle-mvn-push.gradle') 4 | 5 | dependencies { 6 | implementation fileTree(dir: 'libs', include: ['*.jar']) 7 | 8 | compileOnly 'com.google.code.findbugs:jsr305:3.0.2' 9 | implementation 'com.squareup.okhttp3:okhttp:4.3.1' // impl 10 | api 'com.nytimes.android:cache:2.1.1' // impl 11 | 12 | api project(':aws-android-sdk-appsync-api') // api 13 | } 14 | 15 | publishing { 16 | publications { 17 | pluginPublication(MavenPublication) { 18 | from components.java 19 | groupId 'com.amazonaws' 20 | artifactId 'aws-android-sdk-appsync-runtime' 21 | version VERSION_NAME + "-SNAPSHOT" 22 | } 23 | } 24 | } 25 | 26 | sourceCompatibility = "1.7" 27 | targetCompatibility = "1.7" 28 | 29 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=aws-android-sdk-appsync-runtime 2 | POM_NAME=AWS Android SDK - AppSync GraphQL Runtime 3 | POM_DESCRIPTION=AWS AppSync GraphQL runtime library to support generated code 4 | POM_PACKAGING=jar 5 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/amazonaws/mobileconnectors/appsync/AppSyncQueryWatcher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import com.apollographql.apollo.GraphQLCall; 11 | import com.apollographql.apollo.api.Operation; 12 | import com.apollographql.apollo.fetcher.ResponseFetcher; 13 | import com.apollographql.apollo.internal.util.Cancelable; 14 | 15 | import javax.annotation.Nonnull; 16 | import javax.annotation.Nullable; 17 | 18 | public interface AppSyncQueryWatcher extends Cancelable { 19 | 20 | AppSyncQueryWatcher enqueueAndWatch(@Nullable final GraphQLCall.Callback callback); 21 | 22 | /** 23 | * @param fetcher The {@link ResponseFetcher} to use when the call is refetched due to a field changing in the 24 | * cache. 25 | */ 26 | @Nonnull 27 | AppSyncQueryWatcher refetchResponseFetcher(@Nonnull ResponseFetcher fetcher); 28 | 29 | /** 30 | * Returns GraphQL watched operation. 31 | * 32 | * @return {@link Operation} 33 | */ 34 | @Nonnull Operation operation(); 35 | 36 | /** 37 | * Re-fetches watched GraphQL query. 38 | */ 39 | void refetch(); 40 | 41 | /** 42 | * Cancels this {@link AppSyncQueryWatcher}. The {@link GraphQLCall.Callback} 43 | * will be disposed, and will receive no more events. Any active operations will attempt to abort and 44 | * release resources, if possible. 45 | */ 46 | @Override void cancel(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/amazonaws/mobileconnectors/appsync/AppSyncSubscriptionCall.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import com.apollographql.apollo.api.Response; 11 | import com.apollographql.apollo.api.Subscription; 12 | import com.apollographql.apollo.exception.ApolloException; 13 | import com.apollographql.apollo.internal.util.Cancelable; 14 | 15 | import javax.annotation.Nonnull; 16 | 17 | public interface AppSyncSubscriptionCall extends Cancelable { 18 | void execute(@Nonnull Callback callback); 19 | 20 | AppSyncSubscriptionCall clone(); 21 | 22 | interface Factory { 23 | AppSyncSubscriptionCall subscribe( 24 | @Nonnull Subscription subscription); 25 | } 26 | 27 | interface Callback { 28 | 29 | /** 30 | This method is called every time a message is received. 31 | */ 32 | void onResponse(@Nonnull Response response); 33 | 34 | /** 35 | This method is called if there is an error creating subscription or parsing server response. 36 | */ 37 | void onFailure(@Nonnull ApolloException e); 38 | 39 | /** 40 | This method is called when a subscription is terminated. 41 | */ 42 | void onCompleted(); 43 | } 44 | 45 | interface StartedCallback extends Callback { 46 | 47 | /** 48 | This method is called when a subscription first connects successfully. 49 | */ 50 | void onStarted(); 51 | } 52 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/amazonaws/mobileconnectors/appsync/AppSyncSubscriptionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | interface AppSyncSubscriptionListener { 11 | void onMessage(); 12 | } 13 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/amazonaws/mobileconnectors/appsync/subscription/SubscriptionResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.subscription; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class SubscriptionResponse { 14 | public List mqttInfos = new ArrayList<>(); 15 | 16 | public void add(MqttInfo info) { 17 | mqttInfos.add(info); 18 | } 19 | 20 | public static class MqttInfo { 21 | public MqttInfo(String clientId, String wssURL, String[] topics) { 22 | this.clientId = clientId; 23 | this.wssURL = wssURL; 24 | this.topics = topics; 25 | } 26 | public String clientId; 27 | public String wssURL; 28 | public String[] topics; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/IdleResourceCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo; 9 | 10 | /** 11 | * Callback which gets invoked when the resource transitions 12 | * from active to idle state. 13 | */ 14 | public interface IdleResourceCallback { 15 | 16 | /** 17 | * Gets called when the resource transitions from active to idle state. 18 | */ 19 | void onIdle(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/cache/CacheHeaders.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.cache; 9 | 10 | import com.apollographql.apollo.cache.normalized.NormalizedCache; 11 | import com.apollographql.apollo.cache.normalized.Record; 12 | 13 | import java.util.Collections; 14 | import java.util.LinkedHashMap; 15 | import java.util.Map; 16 | 17 | import javax.annotation.Nullable; 18 | 19 | /** 20 | * A key/value collection which is sent with {@link Record} 21 | * from a {@link com.apollographql.apollo.api.Operation} to the 22 | * {@link NormalizedCache}. 23 | * 24 | * For headers which the default {@link NormalizedCache} respect, see 25 | * {@link GraphQLCacheHeaders}. 26 | */ 27 | public final class CacheHeaders { 28 | 29 | private final Map headerMap; 30 | 31 | public static Builder builder() { 32 | return new Builder(); 33 | } 34 | 35 | public static final CacheHeaders NONE = new CacheHeaders(Collections.emptyMap()); 36 | 37 | public static final class Builder { 38 | 39 | private final Map headerMap = new LinkedHashMap<>(); 40 | 41 | public Builder addHeader(String headerName, String headerValue) { 42 | headerMap.put(headerName, headerValue); 43 | return this; 44 | } 45 | 46 | public Builder addHeaders(Map headerMap) { 47 | this.headerMap.putAll(headerMap); 48 | return this; 49 | } 50 | 51 | public CacheHeaders build() { 52 | return new CacheHeaders(headerMap); 53 | } 54 | } 55 | 56 | /** 57 | * @return A {@link Builder} with a copy of this {@link CacheHeaders} values. 58 | */ 59 | public Builder toBuilder() { 60 | Builder builder = builder(); 61 | builder.addHeaders(headerMap); 62 | return builder; 63 | } 64 | 65 | private CacheHeaders(Map headerMap) { 66 | this.headerMap = headerMap; 67 | } 68 | 69 | @Nullable 70 | public String headerValue(String header) { 71 | return headerMap.get(header); 72 | } 73 | 74 | public boolean hasHeader(String headerName) { 75 | return headerMap.containsKey(headerName); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/cache/GraphQLCacheHeaders.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.cache; 9 | 10 | import com.apollographql.apollo.cache.normalized.NormalizedCache; 11 | 12 | /** 13 | * A collection of cache headers that Apollo's implementations of {@link NormalizedCache} respect. 14 | */ 15 | public final class GraphQLCacheHeaders { 16 | 17 | /** 18 | * Records from this request should not be stored in the {@link NormalizedCache}. 19 | */ 20 | public static final String DO_NOT_STORE = "do-not-store"; 21 | 22 | /** 23 | * Records from this request should be evicted after being read. 24 | */ 25 | public static final String EVICT_AFTER_READ = "evict-after-read"; 26 | } 27 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/cache/normalized/CacheKey.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.cache.normalized; 9 | 10 | import javax.annotation.Nonnull; 11 | 12 | import static com.apollographql.apollo.api.internal.Utils.checkNotNull; 13 | 14 | /** 15 | * A key for a {@link Record} used for normalization in a {@link com.apollographql.apollo.cache.normalized.NormalizedCache}. 16 | * If the json object which the {@link Record} corresponds to does not have a suitable 17 | * key, return use {@link #NO_KEY}. 18 | */ 19 | public final class CacheKey { 20 | 21 | public static final CacheKey NO_KEY = new CacheKey(""); 22 | 23 | public static CacheKey from(@Nonnull String key) { 24 | return new CacheKey(checkNotNull(key, "key == null")); 25 | } 26 | 27 | private final String key; 28 | 29 | private CacheKey(@Nonnull String key) { 30 | this.key = key; 31 | } 32 | 33 | public String key() { 34 | return key; 35 | } 36 | 37 | @Override public boolean equals(Object o) { 38 | if (this == o) return true; 39 | if (!(o instanceof CacheKey)) return false; 40 | 41 | CacheKey cacheKey = (CacheKey) o; 42 | 43 | return key.equals(cacheKey.key); 44 | } 45 | 46 | @Override public int hashCode() { 47 | return key.hashCode(); 48 | } 49 | 50 | @Override public String toString() { 51 | return key; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/cache/normalized/CacheKeyResolver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.cache.normalized; 9 | 10 | import com.apollographql.apollo.api.ResponseField; 11 | import com.apollographql.apollo.api.Mutation; 12 | import com.apollographql.apollo.api.Operation; 13 | import com.apollographql.apollo.api.Query; 14 | import com.apollographql.apollo.api.Subscription; 15 | 16 | import java.util.Map; 17 | 18 | import javax.annotation.Nonnull; 19 | 20 | /** 21 | * Resolves a cache key for a JSON object. 22 | */ 23 | public abstract class CacheKeyResolver { 24 | public static final CacheKeyResolver DEFAULT = new CacheKeyResolver() { 25 | @Nonnull @Override 26 | public CacheKey fromFieldRecordSet(@Nonnull ResponseField field, @Nonnull Map recordSet) { 27 | return CacheKey.NO_KEY; 28 | } 29 | 30 | @Nonnull @Override 31 | public CacheKey fromFieldArguments(@Nonnull ResponseField field, @Nonnull Operation.Variables variables) { 32 | return CacheKey.NO_KEY; 33 | } 34 | }; 35 | public static final CacheKey QUERY_ROOT_KEY = CacheKey.from("QUERY_ROOT"); 36 | public static final CacheKey MUTATION_ROOT_KEY = CacheKey.from("MUTATION_ROOT"); 37 | public static final CacheKey SUBSCRIPTION_ROOT_KEY = CacheKey.from("SUBSCRIPTION_ROOT"); 38 | 39 | public static CacheKey rootKeyForOperation(@Nonnull Operation operation) { 40 | if (operation instanceof Query) { 41 | return QUERY_ROOT_KEY; 42 | } else if (operation instanceof Mutation) { 43 | return MUTATION_ROOT_KEY; 44 | } else if (operation instanceof Subscription) { 45 | return SUBSCRIPTION_ROOT_KEY; 46 | } 47 | throw new IllegalArgumentException("Unknown operation type."); 48 | } 49 | 50 | @Nonnull public abstract CacheKey fromFieldRecordSet(@Nonnull ResponseField field, 51 | @Nonnull Map recordSet); 52 | 53 | @Nonnull public abstract CacheKey fromFieldArguments(@Nonnull ResponseField field, 54 | @Nonnull Operation.Variables variables); 55 | } 56 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/cache/normalized/CacheReference.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.cache.normalized; 9 | 10 | import java.util.regex.Matcher; 11 | import java.util.regex.Pattern; 12 | 13 | public final class CacheReference { 14 | 15 | private final String key; 16 | private static final Pattern SERIALIZATION_REGEX_PATTERN = Pattern.compile("ApolloCacheReference\\{(.*)\\}"); 17 | private static final String SERIALIZATION_TEMPLATE = "ApolloCacheReference{%s}"; 18 | 19 | public CacheReference(String key) { 20 | this.key = key; 21 | } 22 | 23 | public String key() { 24 | return key; 25 | } 26 | 27 | @Override public boolean equals(Object o) { 28 | if (this == o) return true; 29 | if (o == null || getClass() != o.getClass()) return false; 30 | 31 | CacheReference that = (CacheReference) o; 32 | 33 | return key != null ? key.equals(that.key) : that.key == null; 34 | 35 | } 36 | 37 | @Override public int hashCode() { 38 | return key != null ? key.hashCode() : 0; 39 | } 40 | 41 | @Override public String toString() { 42 | return key; 43 | } 44 | 45 | public String serialize() { 46 | return String.format(SERIALIZATION_TEMPLATE, key); 47 | } 48 | 49 | public static CacheReference deserialize(String serializedCacheReference) { 50 | Matcher matcher = SERIALIZATION_REGEX_PATTERN.matcher(serializedCacheReference); 51 | if (!matcher.find() || matcher.groupCount() != 1) { 52 | throw new IllegalArgumentException("Not a cache reference: " + serializedCacheReference 53 | + " Must be of the form:" + SERIALIZATION_TEMPLATE); 54 | } 55 | return new CacheReference(matcher.group(1)); 56 | } 57 | 58 | public static boolean canDeserialize(String value) { 59 | Matcher matcher = SERIALIZATION_REGEX_PATTERN.matcher(value); 60 | return matcher.matches(); 61 | } 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/cache/normalized/RecordSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.cache.normalized; 9 | 10 | import java.util.Collection; 11 | import java.util.Collections; 12 | import java.util.LinkedHashMap; 13 | import java.util.Map; 14 | import java.util.Set; 15 | 16 | public final class RecordSet { 17 | 18 | private final Map recordMap = new LinkedHashMap<>(); 19 | 20 | public Record get(String key) { 21 | return recordMap.get(key); 22 | } 23 | 24 | public Set merge(Record apolloRecord) { 25 | final Record oldRecord = recordMap.get(apolloRecord.key()); 26 | if (oldRecord == null) { 27 | recordMap.put(apolloRecord.key(), apolloRecord); 28 | return Collections.emptySet(); 29 | } else { 30 | return oldRecord.mergeWith(apolloRecord); 31 | } 32 | } 33 | 34 | public Collection allRecords() { 35 | return recordMap.values(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/cache/normalized/lru/LruNormalizedCacheFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.cache.normalized.lru; 9 | 10 | import com.apollographql.apollo.cache.normalized.NormalizedCacheFactory; 11 | import com.apollographql.apollo.cache.normalized.RecordFieldJsonAdapter; 12 | 13 | import static com.apollographql.apollo.api.internal.Utils.checkNotNull; 14 | 15 | public final class LruNormalizedCacheFactory extends NormalizedCacheFactory { 16 | private final EvictionPolicy evictionPolicy; 17 | 18 | /** 19 | * @param evictionPolicy {@link EvictionPolicy} to manage the primary cache. 20 | */ 21 | public LruNormalizedCacheFactory(EvictionPolicy evictionPolicy) { 22 | this.evictionPolicy = checkNotNull(evictionPolicy, "evictionPolicy == null"); 23 | } 24 | 25 | @Override public LruNormalizedCache create(final RecordFieldJsonAdapter fieldAdapter) { 26 | return new LruNormalizedCache(evictionPolicy); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/exception/ApolloCanceledException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.exception; 9 | 10 | public final class ApolloCanceledException extends ApolloException { 11 | 12 | public ApolloCanceledException(String message) { 13 | super(message); 14 | } 15 | 16 | public ApolloCanceledException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/exception/ApolloException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.exception; 9 | 10 | public class ApolloException extends Exception { 11 | 12 | public ApolloException(String message) { 13 | super(message); 14 | } 15 | 16 | public ApolloException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/exception/ApolloHttpException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.exception; 9 | 10 | import javax.annotation.Nullable; 11 | 12 | import okhttp3.Response; 13 | 14 | public final class ApolloHttpException extends ApolloException { 15 | private final int code; 16 | private final String message; 17 | private final transient Response rawResponse; 18 | 19 | public ApolloHttpException(@Nullable Response rawResponse) { 20 | super(formatMessage(rawResponse)); 21 | this.code = rawResponse != null ? rawResponse.code() : 0; 22 | this.message = rawResponse != null ? rawResponse.message() : ""; 23 | this.rawResponse = rawResponse; 24 | } 25 | 26 | public int code() { 27 | return code; 28 | } 29 | 30 | public String message() { 31 | return message; 32 | } 33 | 34 | @Nullable public Response rawResponse() { 35 | return rawResponse; 36 | } 37 | 38 | private static String formatMessage(Response response) { 39 | if (response == null) { 40 | return "Empty HTTP response"; 41 | } 42 | return "HTTP " + response.code() + " " + response.message(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/exception/ApolloNetworkException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.exception; 9 | 10 | public final class ApolloNetworkException extends ApolloException { 11 | public ApolloNetworkException(String message) { 12 | super(message); 13 | } 14 | 15 | public ApolloNetworkException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/exception/ApolloParseException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.exception; 9 | 10 | public final class ApolloParseException extends ApolloException { 11 | 12 | public ApolloParseException(String message) { 13 | super(message); 14 | } 15 | 16 | public ApolloParseException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/fetcher/ResponseFetcher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.fetcher; 9 | 10 | import com.amazonaws.mobileconnectors.appsync.fetcher.AppSyncResponseFetchers; 11 | import com.apollographql.apollo.interceptor.ApolloInterceptor; 12 | import com.apollographql.apollo.internal.ApolloLogger; 13 | 14 | /** 15 | * A ResponseFetcher is an {@link ApolloInterceptor} inserted at the beginning of a request chain. 16 | * It can control how a request is fetched by configuring {@link com.apollographql.apollo.interceptor.FetchOptions}. 17 | * 18 | * See {@link AppSyncResponseFetchers} for a basic set of fetchers. 19 | */ 20 | public interface ResponseFetcher { 21 | 22 | /** 23 | * @param logger A {@link ApolloLogger} to log relevant fetch information. 24 | * @return The {@link ApolloInterceptor} that executes the fetch logic. 25 | */ 26 | ApolloInterceptor provideInterceptor(ApolloLogger logger); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/interceptor/ApolloInterceptorChain.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.interceptor; 9 | 10 | import java.util.concurrent.Executor; 11 | 12 | import javax.annotation.Nonnull; 13 | 14 | /** 15 | * ApolloInterceptorChain is responsible for building chain of {@link ApolloInterceptor} . 16 | */ 17 | public interface ApolloInterceptorChain { 18 | /** 19 | * Passes the control over to the next {@link ApolloInterceptor} in the responsibility chain and immediately exits as 20 | * this is a non blocking call. In order to receive the results back, pass in a callback which will handle the 21 | * received response or error. 22 | * 23 | * @param request outgoing request object. 24 | * @param dispatcher the {@link Executor} which dispatches the calls asynchronously. 25 | * @param callBack the callback which will handle the response or a failure exception. 26 | */ 27 | void proceedAsync(@Nonnull ApolloInterceptor.InterceptorRequest request, @Nonnull Executor dispatcher, 28 | @Nonnull ApolloInterceptor.CallBack callBack); 29 | 30 | /** 31 | * Disposes of the resources which are no longer required. 32 | */ 33 | void dispose(); 34 | } 35 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/CallState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal; 9 | 10 | enum CallState { 11 | IDLE, ACTIVE, TERMINATED, CANCELED; 12 | 13 | static class IllegalStateMessage { 14 | private final CallState callState; 15 | 16 | private IllegalStateMessage(CallState callState) { 17 | this.callState = callState; 18 | } 19 | 20 | static IllegalStateMessage forCurrentState(CallState callState) { 21 | return new IllegalStateMessage(callState); 22 | } 23 | 24 | String expected(CallState... acceptableStates) { 25 | StringBuilder stringBuilder = new StringBuilder("Expected: " + callState.name() + ", but found ["); 26 | String deliminator = ""; 27 | for (CallState state : acceptableStates) { 28 | stringBuilder.append(deliminator).append(state.name()); 29 | deliminator = ", "; 30 | } 31 | return stringBuilder.append("]").toString(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/ResponseFieldMapperFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal; 9 | 10 | import com.apollographql.apollo.api.Operation; 11 | import com.apollographql.apollo.api.ResponseFieldMapper; 12 | 13 | import java.util.concurrent.ConcurrentHashMap; 14 | 15 | import javax.annotation.Nonnull; 16 | 17 | import static com.apollographql.apollo.api.internal.Utils.checkNotNull; 18 | 19 | public final class ResponseFieldMapperFactory { 20 | private final ConcurrentHashMap pool = new ConcurrentHashMap<>(); 21 | 22 | @Nonnull public ResponseFieldMapper create(@Nonnull Operation operation) { 23 | checkNotNull(operation, "operation == null"); 24 | Class operationClass = operation.getClass(); 25 | ResponseFieldMapper mapper = pool.get(operationClass); 26 | if (mapper != null) { 27 | return mapper; 28 | } 29 | pool.putIfAbsent(operationClass, operation.responseFieldMapper()); 30 | return pool.get(operationClass); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/cache/normalized/CacheKeyBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.cache.normalized; 9 | 10 | import com.apollographql.apollo.api.Operation; 11 | import com.apollographql.apollo.api.ResponseField; 12 | 13 | import javax.annotation.Nonnull; 14 | 15 | public interface CacheKeyBuilder { 16 | @Nonnull String build(@Nonnull ResponseField field, @Nonnull Operation.Variables variables); 17 | } 18 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/cache/normalized/ReadableStore.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.cache.normalized; 9 | 10 | import com.apollographql.apollo.cache.CacheHeaders; 11 | import com.apollographql.apollo.cache.normalized.Record; 12 | 13 | import java.util.Collection; 14 | 15 | import javax.annotation.Nonnull; 16 | import javax.annotation.Nullable; 17 | 18 | public interface ReadableStore { 19 | 20 | @Nullable Record read(@Nonnull String key, @Nonnull CacheHeaders cacheHeaders); 21 | 22 | Collection read(@Nonnull Collection keys, @Nonnull CacheHeaders cacheHeaders); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/cache/normalized/RecordWeigher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.cache.normalized; 9 | 10 | import com.apollographql.apollo.cache.normalized.CacheReference; 11 | import com.apollographql.apollo.cache.normalized.Record; 12 | 13 | import java.math.BigDecimal; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | public final class RecordWeigher { 18 | 19 | private static final int SIZE_OF_BOOLEAN = 16; 20 | private static final int SIZE_OF_BIG_DECIMAL = 32; 21 | private static final int SIZE_OF_ARRAY_OVERHEAD = 16; 22 | private static final int SIZE_OF_RECORD_OVERHEAD = 16; 23 | private static final int SIZE_OF_CACHE_REFERENCE_OVERHEAD = 16; 24 | private static final int SIZE_OF_NULL = 4; 25 | 26 | public static int byteChange(Object newValue, Object oldValue) { 27 | return weighField(newValue) - weighField(oldValue); 28 | } 29 | 30 | public static int calculateBytes(Record record) { 31 | int size = SIZE_OF_RECORD_OVERHEAD + record.key().getBytes().length; 32 | for (Map.Entry field : record.fields().entrySet()) { 33 | size += (field.getKey().getBytes().length + weighField(field.getValue())); 34 | } 35 | return size; 36 | } 37 | 38 | private static int weighField(Object field) { 39 | if (field instanceof List) { 40 | int size = SIZE_OF_ARRAY_OVERHEAD; 41 | for (Object listItem : (List) field) { 42 | size += weighField(listItem); 43 | } 44 | return size; 45 | } 46 | if (field instanceof String) { 47 | return ((String) field).getBytes().length; 48 | } else if (field instanceof Boolean) { 49 | return SIZE_OF_BOOLEAN; 50 | } else if (field instanceof BigDecimal) { 51 | return SIZE_OF_BIG_DECIMAL; 52 | } else if (field instanceof CacheReference) { 53 | return SIZE_OF_CACHE_REFERENCE_OVERHEAD + ((CacheReference) field).key().getBytes().length; 54 | } else if (field == null) { 55 | return SIZE_OF_NULL; 56 | } 57 | throw new IllegalStateException("Unknown field type in Record. " + field.getClass().getName()); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/cache/normalized/Transaction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.cache.normalized; 9 | 10 | import javax.annotation.Nullable; 11 | 12 | @SuppressWarnings("WeakerAccess") public interface Transaction { 13 | @Nullable R execute(T cache); 14 | } 15 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/cache/normalized/WriteableStore.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.cache.normalized; 9 | 10 | import com.apollographql.apollo.cache.CacheHeaders; 11 | import com.apollographql.apollo.cache.normalized.Record; 12 | 13 | import java.util.Collection; 14 | import java.util.Set; 15 | 16 | import javax.annotation.Nonnull; 17 | 18 | public interface WriteableStore extends ReadableStore { 19 | 20 | Set merge(@Nonnull Collection recordCollection, @Nonnull CacheHeaders cacheHeaders); 21 | Set merge(Record record, @Nonnull CacheHeaders cacheHeaders); 22 | } 23 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/fetcher/NetworkOnlyFetcher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.fetcher; 9 | 10 | import com.apollographql.apollo.fetcher.ResponseFetcher; 11 | import com.apollographql.apollo.interceptor.ApolloInterceptor; 12 | import com.apollographql.apollo.interceptor.ApolloInterceptorChain; 13 | import com.apollographql.apollo.internal.ApolloLogger; 14 | 15 | import java.util.concurrent.Executor; 16 | 17 | import javax.annotation.Nonnull; 18 | 19 | /** 20 | * Signals the apollo client to only fetch the GraphQL data from the network. If network request fails, an 21 | * exception is thrown. 22 | */ 23 | public final class NetworkOnlyFetcher implements ResponseFetcher { 24 | 25 | @Override public ApolloInterceptor provideInterceptor(ApolloLogger apolloLogger) { 26 | return new NetworkOnlyInterceptor(); 27 | } 28 | 29 | private static final class NetworkOnlyInterceptor implements ApolloInterceptor { 30 | @Override 31 | public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain, 32 | @Nonnull Executor dispatcher, @Nonnull CallBack callBack) { 33 | InterceptorRequest networkRequest = request.toBuilder().fetchFromCache(false).build(); 34 | chain.proceedAsync(networkRequest, dispatcher, callBack); 35 | } 36 | 37 | @Override public void dispose() { 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/field/FieldValueResolver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.field; 9 | 10 | import com.apollographql.apollo.api.ResponseField; 11 | 12 | public interface FieldValueResolver { 13 | T valueFor(R recordSet, ResponseField field); 14 | } 15 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/field/MapFieldValueResolver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.field; 9 | 10 | import com.apollographql.apollo.api.ResponseField; 11 | 12 | import java.util.Map; 13 | 14 | public final class MapFieldValueResolver implements FieldValueResolver> { 15 | 16 | @SuppressWarnings("unchecked") @Override public T valueFor(Map map, ResponseField field) { 17 | return (T) map.get(field.responseName()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/interceptor/RealApolloInterceptorChain.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.interceptor; 9 | 10 | import com.apollographql.apollo.interceptor.ApolloInterceptor; 11 | import com.apollographql.apollo.interceptor.ApolloInterceptorChain; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.concurrent.Executor; 16 | 17 | import javax.annotation.Nonnull; 18 | 19 | import static com.apollographql.apollo.api.internal.Utils.checkNotNull; 20 | 21 | /** 22 | * RealApolloInterceptorChain is responsible for building the entire interceptor chain. Based on the task at hand, the 23 | * chain may contain interceptors which fetch responses from the normalized cache, make network calls to fetch data if 24 | * needed or parse the http responses to inflate models. 25 | */ 26 | public final class RealApolloInterceptorChain implements ApolloInterceptorChain { 27 | private final List interceptors; 28 | private final int interceptorIndex; 29 | 30 | public RealApolloInterceptorChain(@Nonnull List interceptors) { 31 | this(interceptors, 0); 32 | } 33 | 34 | private RealApolloInterceptorChain(List interceptors, int interceptorIndex) { 35 | if (interceptorIndex > interceptors.size()) throw new IllegalArgumentException(); 36 | this.interceptors = new ArrayList<>(checkNotNull(interceptors, "interceptors == null")); 37 | this.interceptorIndex = interceptorIndex; 38 | } 39 | 40 | @Override public void proceedAsync(@Nonnull ApolloInterceptor.InterceptorRequest request, 41 | @Nonnull Executor dispatcher, @Nonnull ApolloInterceptor.CallBack callBack) { 42 | if (interceptorIndex >= interceptors.size()) throw new IllegalStateException(); 43 | interceptors.get(interceptorIndex).interceptAsync(request, new RealApolloInterceptorChain(interceptors, 44 | interceptorIndex + 1), dispatcher, callBack); 45 | } 46 | 47 | @Override public void dispose() { 48 | for (ApolloInterceptor interceptor : interceptors) { 49 | interceptor.dispose(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/json/ApolloJsonReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.json; 9 | 10 | import okio.BufferedSource; 11 | 12 | public final class ApolloJsonReader { 13 | 14 | public static CacheJsonStreamReader cacheJsonStreamReader(BufferedSourceJsonReader sourceJsonReader) { 15 | return new CacheJsonStreamReader(sourceJsonReader); 16 | } 17 | 18 | public static ResponseJsonStreamReader responseJsonStreamReader(BufferedSourceJsonReader sourceJsonReader) { 19 | return new ResponseJsonStreamReader(sourceJsonReader); 20 | } 21 | 22 | public static BufferedSourceJsonReader bufferedSourceJsonReader(BufferedSource bufferedSource) { 23 | return new BufferedSourceJsonReader(bufferedSource); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/json/CacheJsonStreamReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.json; 9 | 10 | import com.apollographql.apollo.cache.normalized.CacheReference; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * A {@link ResponseJsonStreamReader} with additional support for {@link CacheReference}. 16 | */ 17 | public final class CacheJsonStreamReader extends ResponseJsonStreamReader { 18 | 19 | public CacheJsonStreamReader(JsonReader jsonReader) { 20 | super(jsonReader); 21 | } 22 | 23 | @Override public Object nextScalar(boolean optional) throws IOException { 24 | Object scalar = super.nextScalar(optional); 25 | if (scalar instanceof String) { 26 | String scalarString = (String) scalar; 27 | if (CacheReference.canDeserialize(scalarString)) { 28 | return CacheReference.deserialize(scalarString); 29 | } 30 | } 31 | return scalar; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/json/Utils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.json; 9 | 10 | import java.io.IOException; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | import javax.annotation.Nonnull; 15 | 16 | import okio.Buffer; 17 | 18 | import static com.apollographql.apollo.api.internal.Utils.checkNotNull; 19 | 20 | public final class Utils { 21 | 22 | public static String toJsonString(@Nonnull Object data) throws IOException { 23 | checkNotNull(data, "data == null"); 24 | 25 | Buffer buffer = new Buffer(); 26 | JsonWriter jsonWriter = JsonWriter.of(buffer); 27 | writeToJson(data, jsonWriter); 28 | jsonWriter.close(); 29 | 30 | return buffer.readUtf8(); 31 | } 32 | 33 | @SuppressWarnings("unchecked") 34 | public static void writeToJson(Object value, JsonWriter jsonWriter) throws IOException { 35 | if (value == null) { 36 | jsonWriter.nullValue(); 37 | } else if (value instanceof Map) { 38 | jsonWriter.beginObject(); 39 | for (Map.Entry entry : ((Map) value).entrySet()) { 40 | String key = entry.getKey().toString(); 41 | jsonWriter.name(key); 42 | writeToJson(entry.getValue(), jsonWriter); 43 | } 44 | jsonWriter.endObject(); 45 | } else if (value instanceof List) { 46 | jsonWriter.beginArray(); 47 | for (Object item : (List) value) { 48 | writeToJson(item, jsonWriter); 49 | } 50 | jsonWriter.endArray(); 51 | } else if (value instanceof Boolean) { 52 | jsonWriter.value((Boolean) value); 53 | } else if (value instanceof Number) { 54 | jsonWriter.value((Number) value); 55 | } else { 56 | jsonWriter.value(value.toString()); 57 | } 58 | } 59 | 60 | private Utils() { 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/response/ResponseReaderShadow.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.response; 9 | 10 | import com.apollographql.apollo.api.ResponseField; 11 | import com.apollographql.apollo.api.Operation; 12 | import com.apollographql.apollo.api.internal.Optional; 13 | 14 | import java.util.List; 15 | 16 | public interface ResponseReaderShadow { 17 | 18 | void willResolveRootQuery(Operation operation); 19 | 20 | void willResolve(ResponseField field, Operation.Variables variables); 21 | 22 | void didResolve(ResponseField field, Operation.Variables variables); 23 | 24 | void didResolveScalar(Object value); 25 | 26 | void willResolveObject(ResponseField objectField, Optional objectSource); 27 | 28 | void didResolveObject(ResponseField objectField, Optional objectSource); 29 | 30 | void didResolveList(List array); 31 | 32 | void willResolveElement(int atIndex); 33 | 34 | void didResolveElement(int atIndex); 35 | 36 | void didResolveNull(); 37 | } 38 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/subscription/NoOpSubscriptionManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.subscription; 9 | 10 | import com.amazonaws.mobileconnectors.appsync.AppSyncSubscriptionCall; 11 | import com.amazonaws.mobileconnectors.appsync.subscription.SubscriptionResponse; 12 | import com.apollographql.apollo.api.Subscription; 13 | import com.apollographql.apollo.cache.normalized.ApolloStore; 14 | import com.apollographql.apollo.internal.cache.normalized.ResponseNormalizer; 15 | import com.apollographql.apollo.internal.response.ScalarTypeAdapters; 16 | 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | import javax.annotation.Nonnull; 21 | 22 | public final class NoOpSubscriptionManager implements SubscriptionManager { 23 | 24 | @Override 25 | public void subscribe(@Nonnull Subscription subscription, @Nonnull List subbedTopics, @Nonnull SubscriptionResponse response, ResponseNormalizer> mapResponseNormalizer) { 26 | 27 | } 28 | 29 | @Override public void unsubscribe(@Nonnull Subscription subscription) { 30 | throw new IllegalStateException("Subscription manager is not configured"); 31 | } 32 | 33 | @Override 34 | public void addListener(Subscription subscription, AppSyncSubscriptionCall.Callback callback) { 35 | 36 | } 37 | 38 | @Override 39 | public void removeListener(Subscription subscription, AppSyncSubscriptionCall.Callback callback) { 40 | 41 | } 42 | 43 | @Override 44 | public void setStore(ApolloStore apolloStore) { 45 | 46 | } 47 | 48 | @Override 49 | public void setScalarTypeAdapters(ScalarTypeAdapters scalarTypeAdapters) { 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/util/Cancelable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.util; 9 | 10 | /** 11 | * Represents an operation which can be canceled. 12 | */ 13 | public interface Cancelable { 14 | /** 15 | * Cancels the operation. 16 | */ 17 | void cancel(); 18 | 19 | /** 20 | * Checks if this operation has been canceled. 21 | * 22 | * @return true if this operation has been canceled else returns false 23 | */ 24 | boolean isCanceled(); 25 | } 26 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/util/SimpleStack.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.internal.util; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * Simple stack data structure which accepts null elements. Backed by list. 15 | * @param 16 | */ 17 | public class SimpleStack { 18 | 19 | private List backing; 20 | 21 | public SimpleStack() { 22 | backing = new ArrayList<>(); 23 | } 24 | 25 | public SimpleStack(int initialSize) { 26 | backing = new ArrayList<>(initialSize); 27 | } 28 | 29 | public void push(E element) { 30 | backing.add(element); 31 | } 32 | 33 | public E pop() { 34 | if (isEmpty()) { 35 | throw new IllegalStateException("Stack is empty."); 36 | } 37 | return backing.remove(backing.size() - 1); 38 | } 39 | 40 | public boolean isEmpty() { 41 | return backing.isEmpty(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/json/JsonDataException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /* 9 | * Copyright (C) 2015 Square, Inc. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | package com.apollographql.apollo.json; 24 | 25 | import com.apollographql.apollo.internal.json.JsonReader; 26 | 27 | /** 28 | * Thrown when the data in a JSON document doesn't match the data expected by the caller. For 29 | * example, suppose the application expects a boolean but the JSON document contains a string. When 30 | * the call to {@link JsonReader#nextBoolean} is made, a {@code JsonDataException} is thrown. 31 | * 32 | *

Exceptions of this type should be fixed by either changing the application code to accept 33 | * the unexpected JSON, or by changing the JSON to conform to the application's expectations. 34 | * 35 | *

This exception may also be triggered if a document's nesting exceeds 31 levels. This depth is 36 | * sufficient for all practical applications, but shallow enough to avoid uglier failures like 37 | * {@link StackOverflowError}. 38 | */ 39 | public final class JsonDataException extends RuntimeException { 40 | public JsonDataException() { 41 | } 42 | 43 | public JsonDataException(String message) { 44 | super(message); 45 | } 46 | 47 | public JsonDataException(Throwable cause) { 48 | super(cause); 49 | } 50 | 51 | public JsonDataException(String message, Throwable cause) { 52 | super(message, cause); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/json/JsonEncodingException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /* 9 | * Copyright (C) 2016 Square, Inc. 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | package com.apollographql.apollo.json; 24 | 25 | import java.io.IOException; 26 | 27 | /** Thrown when the data being parsed is not encoded as valid JSON. */ 28 | public final class JsonEncodingException extends IOException { 29 | public JsonEncodingException(String message) { 30 | super(message); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | appsync_test_credentials.json 3 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.amazonaws.appsync' 3 | 4 | buildscript { 5 | ext.aws_version = AWS_CORE_SDK_VERSION 6 | 7 | repositories { 8 | mavenLocal() 9 | maven { 10 | url "https://plugins.gradle.org/m2/" 11 | } 12 | google() 13 | mavenCentral() 14 | } 15 | 16 | dependencies { 17 | classpath "com.amazonaws:aws-android-sdk-appsync-gradle-plugin:$VERSION_NAME" 18 | classpath 'com.android.tools.build:gradle:4.0.0' 19 | } 20 | } 21 | 22 | android { 23 | compileSdkVersion 28 24 | 25 | defaultConfig { 26 | minSdkVersion 21 27 | targetSdkVersion 28 28 | versionCode 1 29 | versionName "1.0" 30 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 31 | } 32 | 33 | buildTypes { 34 | release { 35 | minifyEnabled false 36 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 37 | } 38 | } 39 | 40 | compileOptions { 41 | sourceCompatibility JavaVersion.VERSION_1_8 42 | targetCompatibility JavaVersion.VERSION_1_8 43 | } 44 | } 45 | 46 | repositories { 47 | mavenLocal() 48 | maven { 49 | url "https://plugins.gradle.org/m2/" 50 | } 51 | google() 52 | mavenCentral() 53 | } 54 | 55 | dependencies { 56 | androidTestImplementation 'androidx.core:core:1.0.0' 57 | androidTestImplementation 'androidx.test:runner:1.1.0' 58 | androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' 59 | androidTestImplementation 'junit:junit:4.13' 60 | androidTestImplementation "com.amazonaws:aws-android-sdk-s3:$aws_version" 61 | androidTestImplementation "com.amazonaws:aws-android-sdk-appsync:$VERSION_NAME" 62 | androidTestImplementation ("com.amazonaws:aws-android-sdk-mobile-client:$aws_version@aar") { transitive = true } 63 | androidTestImplementation ("com.amazonaws:aws-android-sdk-auth-userpools:$aws_version@aar") { transitive = true } 64 | androidTestImplementation ("com.amazonaws:aws-android-sdk-cognitoauth:$aws_version@aar") 65 | } 66 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | org.gradle.parallel=true 14 | 15 | GROUP=com.amazonaws 16 | VERSION_NAME=3.1.3-SNAPSHOT 17 | AWS_CORE_SDK_VERSION=2.16.8 18 | 19 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/aws-android-sdk-appsync-tests/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/proguard-rules.pro: -------------------------------------------------------------------------------- 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 22 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/settings.gradle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/aws-android-sdk-appsync-tests/settings.gradle -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/SyncStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import static com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient.DATABASE_NAME_DELIMITER; 11 | import static com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient.DEFAULT_DELTA_SYNC_SQL_STORE_NAME; 12 | import static com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient.DEFAULT_MUTATION_SQL_STORE_NAME; 13 | import static com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient.DEFAULT_QUERY_SQL_STORE_NAME; 14 | import static org.junit.Assert.assertEquals; 15 | import static org.junit.Assert.assertNotNull; 16 | 17 | /** 18 | * This utility must live in the same package as {@link AWSAppSyncClient}, 19 | * since it accesses package-visibility fields on the {@link AWSAppSyncClient}. 20 | */ 21 | public final class SyncStore { 22 | private SyncStore() {} 23 | 24 | public static void validate(AWSAppSyncClient client, String clientDatabasePrefix) { 25 | assertNotNull(client.mSyncStore); 26 | if (clientDatabasePrefix != null) { 27 | assertEquals( 28 | clientDatabasePrefix + DATABASE_NAME_DELIMITER + DEFAULT_QUERY_SQL_STORE_NAME, 29 | client.querySqlStoreName 30 | ); 31 | assertEquals( 32 | clientDatabasePrefix + DATABASE_NAME_DELIMITER + DEFAULT_MUTATION_SQL_STORE_NAME, 33 | client.mutationSqlStoreName 34 | ); 35 | assertEquals( 36 | clientDatabasePrefix + DATABASE_NAME_DELIMITER + DEFAULT_DELTA_SYNC_SQL_STORE_NAME, 37 | client.deltaSyncSqlStoreName 38 | ); 39 | } else { 40 | assertEquals(DEFAULT_QUERY_SQL_STORE_NAME, client.querySqlStoreName); 41 | assertEquals(DEFAULT_MUTATION_SQL_STORE_NAME, client.mutationSqlStoreName); 42 | assertEquals(DEFAULT_DELTA_SYNC_SQL_STORE_NAME, client.deltaSyncSqlStoreName); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/client/DelegatingGraphQLCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.client; 9 | 10 | import androidx.annotation.NonNull; 11 | 12 | import com.amazonaws.mobileconnectors.appsync.util.Consumer; 13 | import com.apollographql.apollo.GraphQLCall; 14 | import com.apollographql.apollo.api.Response; 15 | import com.apollographql.apollo.exception.ApolloException; 16 | 17 | /** 18 | * An {@link GraphQLCall.Callback} which works by passing any received values 19 | * to delegated {@link Consumer}s. For example, if the callback receives an 20 | * {@link Response}, it just passes it to the corresponding {@link Consumer} by calling 21 | * {@link Consumer#accept(T)}. 22 | */ 23 | public final class DelegatingGraphQLCallback extends GraphQLCall.Callback { 24 | private final Consumer> onResponse; 25 | private final Consumer onFailure; 26 | 27 | private DelegatingGraphQLCallback( 28 | @NonNull Consumer> onResponse, 29 | @NonNull Consumer onFailure) { 30 | this.onResponse = onResponse; 31 | this.onFailure = onFailure; 32 | } 33 | 34 | /** 35 | * Creates a GraphQLCall.Callback which will delegate any receives response/failure 36 | * to one of two provided value consumers. The consumers can take it from there. 37 | * @param onResponse Consumer of GraphQL {@link Response} 38 | * @param onFailure Consumer of {@link ApolloException} 39 | * @param Type of data in response 40 | * @return A delegating GraphQLCall.Callback 41 | */ 42 | public static DelegatingGraphQLCallback to( 43 | @NonNull Consumer> onResponse, 44 | @NonNull Consumer onFailure) { 45 | return new DelegatingGraphQLCallback<>(onResponse, onFailure); 46 | } 47 | 48 | @Override 49 | public void onResponse(@NonNull Response response) { 50 | onResponse.accept(response); 51 | } 52 | 53 | @Override 54 | public void onFailure(@NonNull ApolloException failure) { 55 | onFailure.accept(failure); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/client/LoggingPersistentMutationsCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.client; 9 | 10 | import android.util.Log; 11 | 12 | import com.amazonaws.mobileconnectors.appsync.PersistentMutationsCallback; 13 | import com.amazonaws.mobileconnectors.appsync.PersistentMutationsError; 14 | import com.amazonaws.mobileconnectors.appsync.PersistentMutationsResponse; 15 | 16 | final class LoggingPersistentMutationsCallback implements PersistentMutationsCallback { 17 | private static final String TAG = LoggingPersistentMutationsCallback.class.getName(); 18 | 19 | private LoggingPersistentMutationsCallback() {} 20 | 21 | static LoggingPersistentMutationsCallback instance() { 22 | return new LoggingPersistentMutationsCallback(); 23 | } 24 | 25 | @Override 26 | public void onResponse(PersistentMutationsResponse response) { 27 | Log.d(TAG, response.getMutationClassName()); 28 | } 29 | 30 | @Override 31 | public void onFailure(PersistentMutationsError error) { 32 | Log.e(TAG, error.getMutationClassName()); 33 | Log.e(TAG, "Error", error.getException()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/client/NoOpGraphQLCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.client; 9 | 10 | import androidx.annotation.NonNull; 11 | 12 | import com.apollographql.apollo.GraphQLCall; 13 | import com.apollographql.apollo.api.Response; 14 | import com.apollographql.apollo.exception.ApolloException; 15 | 16 | /** 17 | * An {@link GraphQLCall.Callback} that does nothing. 18 | * @param Type of data in the GraphQL response 19 | */ 20 | public final class NoOpGraphQLCallback extends GraphQLCall.Callback { 21 | private NoOpGraphQLCallback() {} 22 | 23 | public static NoOpGraphQLCallback instance() { 24 | return new NoOpGraphQLCallback<>(); 25 | } 26 | 27 | @Override 28 | public void onResponse(@NonNull Response response) { 29 | } 30 | 31 | @Override 32 | public void onFailure(@NonNull ApolloException failure) { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/client/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /** 9 | * This package contains code for interaction with an 10 | * {@link com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient}, 11 | * itself. The {@link com.amazonaws.mobileconnectors.appsync.client.AWSAppSyncClients} 12 | * is a factory class to create various instances of the client, 13 | * permuted by different authentication schemes. 14 | * 15 | * {@link com.amazonaws.mobileconnectors.appsync.client.LatchedGraphQLCallback} 16 | * and {@link com.amazonaws.mobileconnectors.appsync.client.LatchedSubscriptionCallback} 17 | * are useful for making async calls into synchronous calls, so that you can assert 18 | * outcomes after the result is furnished. 19 | * 20 | * {@link com.amazonaws.mobileconnectors.appsync.client.NoOpGraphQLCallback} 21 | * and {@link com.amazonaws.mobileconnectors.appsync.client.DelegatingGraphQLCallback} 22 | * are utility callbacks to reduce boiler-plate by either doing nothing, or by 23 | * supplying lambdas instead of a verbose, anonymous instance 24 | * of {@link com.apollographql.apollo.GraphQLCall.Callback}. 25 | */ 26 | package com.amazonaws.mobileconnectors.appsync.client; 27 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/identity/DelayedCognitoCredentialsProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.identity; 9 | 10 | import android.content.Context; 11 | 12 | import androidx.test.InstrumentationRegistry; 13 | 14 | import com.amazonaws.auth.AWSCredentials; 15 | import com.amazonaws.auth.AWSCredentialsProvider; 16 | import com.amazonaws.auth.CognitoCachingCredentialsProvider; 17 | import com.amazonaws.mobileconnectors.appsync.util.Sleep; 18 | import com.amazonaws.regions.Regions; 19 | 20 | // TODO: Why does this exist? 21 | public final class DelayedCognitoCredentialsProvider implements AWSCredentialsProvider { 22 | private final AWSCredentialsProvider credentialsProvider; 23 | private final long credentialsDelay; 24 | 25 | public DelayedCognitoCredentialsProvider(String cognitoIdentityPoolID, Regions region, long credentialsDelay) { 26 | Context context = InstrumentationRegistry.getContext(); 27 | this.credentialsProvider = new CognitoCachingCredentialsProvider(context, cognitoIdentityPoolID, region); 28 | this.credentialsDelay = credentialsDelay; 29 | } 30 | 31 | @Override 32 | public AWSCredentials getCredentials() { 33 | if (credentialsDelay > 0) { 34 | Sleep.milliseconds(credentialsDelay); 35 | } 36 | return credentialsProvider.getCredentials(); 37 | } 38 | 39 | @Override 40 | public void refresh() { 41 | credentialsProvider.refresh(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/identity/TestAWSMobileClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.identity; 9 | 10 | import android.content.Context; 11 | import androidx.annotation.NonNull; 12 | 13 | import com.amazonaws.mobile.client.AWSMobileClient; 14 | import com.amazonaws.mobile.client.UserStateDetails; 15 | 16 | import java.util.Objects; 17 | 18 | /** 19 | * A wrapper of the {@link AWSMobileClient} which maintains a singleton of the client. 20 | * The singleton instance of the client is initialized in a synchronous way, and is 21 | * usable as soon as it is returned. 22 | */ 23 | public final class TestAWSMobileClient { 24 | private static AWSMobileClient instance; 25 | 26 | public static synchronized AWSMobileClient instance(@NonNull Context context) { 27 | Objects.requireNonNull(context); 28 | if (instance == null) { 29 | LatchedMobileClientCallback callback = LatchedMobileClientCallback.instance(); 30 | AWSMobileClient.getInstance().initialize(context, callback); 31 | callback.awaitResult(); 32 | instance = AWSMobileClient.getInstance(); 33 | } 34 | return instance; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/identity/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /** 9 | * This package deals with Cognito, and the AWSMobileClient, and other 10 | * concerns related to bootstrapping identities. Identities are used 11 | * by the AWSAppSyncClient when making GraphQL requests. 12 | */ 13 | package com.amazonaws.mobileconnectors.appsync.identity; 14 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/models/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /** 9 | * This package contains utilities for interacting with code generated model classes. 10 | * 11 | * {@link com.amazonaws.mobileconnectors.appsync.models.Posts} simplifies CRUD operations 12 | * using an AppSync client. 13 | * 14 | */ 15 | package com.amazonaws.mobileconnectors.appsync.models; 16 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/tests/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /** 9 | * This package contains the actual Android instrumentation test classes 10 | * uses to test AppSync. These files are named like [WhatsBeingTested]InstrumentationTest.java. 11 | */ 12 | package com.amazonaws.mobileconnectors.appsync.tests; 13 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/util/AirplaneMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | package com.amazonaws.mobileconnectors.appsync.util; 8 | 9 | import static androidx.test.InstrumentationRegistry.getInstrumentation; 10 | 11 | import android.content.ContentResolver; 12 | import android.content.Intent; 13 | import android.provider.Settings; 14 | 15 | import androidx.test.uiautomator.By; 16 | import androidx.test.uiautomator.BySelector; 17 | import androidx.test.uiautomator.UiDevice; 18 | import androidx.test.uiautomator.Until; 19 | 20 | public final class AirplaneMode { 21 | private static final int TIMEOUT_MS = 500; 22 | 23 | private AirplaneMode() {} 24 | 25 | public static void enable() { 26 | setAirplaneMode(true); 27 | } 28 | 29 | public static void disable() { 30 | setAirplaneMode(false); 31 | } 32 | 33 | public static boolean isEnabled() { 34 | ContentResolver contentResolver = getInstrumentation().getContext().getContentResolver(); 35 | int status = Settings.System.getInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0); 36 | return status == 1; 37 | } 38 | 39 | private static void setAirplaneMode(boolean shouldEnable) { 40 | if (shouldEnable == isEnabled()) return; 41 | 42 | UiDevice device = UiDevice.getInstance(getInstrumentation()); 43 | device.openQuickSettings(); 44 | 45 | BySelector description = By.desc("Airplane mode"); 46 | device.wait(Until.hasObject(description), TIMEOUT_MS); 47 | device.findObject(description).click(); 48 | 49 | getInstrumentation().getContext() 50 | .sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/util/Consumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.util; 9 | 10 | /** 11 | * A consumer of a value. 12 | * This is inspired by {@link java.util.function.Consumer}, 13 | * which is only available after API 24. 14 | * @param The type of value being consumed 15 | */ 16 | public interface Consumer { 17 | /** 18 | * Accept a value. 19 | * @param value Value being consumed 20 | */ 21 | void accept(V value); 22 | } 23 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/util/DataFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | package com.amazonaws.mobileconnectors.appsync.util; 8 | 9 | import android.content.Context; 10 | import androidx.annotation.NonNull; 11 | import androidx.test.InstrumentationRegistry; 12 | 13 | import java.io.File; 14 | import java.io.FileOutputStream; 15 | import java.io.IOException; 16 | 17 | public final class DataFile { 18 | private DataFile() {} 19 | 20 | @NonNull 21 | public static String create(String fileName, String data) { 22 | Context context = InstrumentationRegistry.getContext(); 23 | File file = new File(context.getCacheDir() + fileName); 24 | try (FileOutputStream fileOutputStream = new FileOutputStream(file)) { 25 | fileOutputStream.write(data.getBytes()); 26 | } catch (IOException ioException) { 27 | throw new RuntimeException(ioException); 28 | } 29 | return file.getAbsolutePath(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/util/InternetConnectivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | package com.amazonaws.mobileconnectors.appsync.util; 8 | 9 | import java.io.IOException; 10 | import java.net.InetSocketAddress; 11 | import java.net.Socket; 12 | import java.util.concurrent.TimeUnit; 13 | 14 | public final class InternetConnectivity { 15 | private InternetConnectivity() {} 16 | 17 | public static void goOnline() { 18 | RetryStrategies.linear(AirplaneMode::disable, InternetConnectivity::isOnline, 3, 2); 19 | } 20 | 21 | public static void goOffline() { 22 | RetryStrategies.linear(AirplaneMode::enable, InternetConnectivity::isOffline, 3, 2); 23 | } 24 | 25 | private static boolean isOnline() { 26 | int connectionTimeoutMs = (int) TimeUnit.SECONDS.toMillis(2); 27 | String host = "amazon.com"; 28 | int port = 443; 29 | 30 | Socket socket = new Socket(); 31 | try { 32 | socket.connect(new InetSocketAddress(host, port), connectionTimeoutMs); 33 | socket.close(); 34 | return true; 35 | } catch (IOException socketFailure) { 36 | return false; 37 | } 38 | } 39 | 40 | private static boolean isOffline() { 41 | return !isOnline(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/util/JsonExtract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.util; 9 | 10 | import org.json.JSONException; 11 | import org.json.JSONObject; 12 | 13 | public final class JsonExtract { 14 | private JsonExtract() {} 15 | 16 | // This is a poor man's implementation of JSONPath, that just handles literals, 17 | // with the '.' meaning "down one more level." This will break if your key contains a period. 18 | public static String stringValue(JSONObject container, String path) { 19 | int indexOfFirstPeriod = path.indexOf("."); 20 | if (indexOfFirstPeriod != -1) { 21 | String firstPortion = path.substring(0, indexOfFirstPeriod); 22 | String rest = path.substring(indexOfFirstPeriod + 1); 23 | 24 | try { 25 | return stringValue(container.getJSONObject(firstPortion), rest); 26 | } catch (JSONException e) { 27 | throw new RuntimeException("could not find " + path); 28 | } 29 | } 30 | try { 31 | return container.getString(path); 32 | } catch (JSONException jsonException) { 33 | throw new RuntimeException( 34 | "Failed to get key " + path + " from " + container + 35 | ", please check that it is correctly formed.", jsonException 36 | ); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/util/RetryStrategies.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.util; 9 | 10 | final class RetryStrategies { 11 | private RetryStrategies() {} 12 | 13 | @SuppressWarnings("SameParameterValue") 14 | static void linear(Retryable action, Condition condition, int maxAttempts, int secondsBetween) { 15 | int attemptsRemaining = maxAttempts; 16 | while (attemptsRemaining > 0) { 17 | if (condition.isMet()) { 18 | return; 19 | } 20 | action.call(); 21 | --attemptsRemaining; 22 | Sleep.seconds(secondsBetween); 23 | } 24 | throw new IllegalStateException("Failed to meet condition."); 25 | } 26 | 27 | @FunctionalInterface 28 | interface Retryable { 29 | void call(); 30 | } 31 | 32 | @FunctionalInterface 33 | interface Condition { 34 | boolean isMet(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/util/Sleep.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.util; 9 | 10 | import java.util.concurrent.TimeUnit; 11 | 12 | /** 13 | * A utility to sleep the calling thread. 14 | * The {@link InterruptedException} thrown by {@link Thread#sleep(long)} is wrapped into an 15 | * {@link RuntimeException} which helps cut down on test code clutter. 16 | */ 17 | public final class Sleep { 18 | private Sleep() {} 19 | 20 | /** 21 | * Sleeps the current thread for a duration of milliseconds. 22 | * @param milliseconds Duration of time to sleep 23 | * @throws RuntimeException If unable to sleep for the requested amount of time 24 | */ 25 | public static void milliseconds(long milliseconds) { 26 | try { 27 | Thread.sleep(milliseconds); 28 | } catch (InterruptedException interruptedException) { 29 | throw new RuntimeException(interruptedException); 30 | } 31 | } 32 | 33 | /** 34 | * Sleeps the current thread for a duration of seconds. 35 | * @param seconds Duration of time to sleep 36 | * @throws RuntimeException If unable to sleep for the requested amount of time 37 | */ 38 | public static void seconds(long seconds) { 39 | milliseconds(TimeUnit.SECONDS.toMillis(seconds)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/androidTest/java/com/amazonaws/mobileconnectors/appsync/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2020 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /** 9 | * This package contains generic utilities that ARE NOT part of the AppSync domain. 10 | * Utilities that have AppSync concerns must find another home, or else this package 11 | * will take on muddled concerns. 12 | * 13 | * {@link com.amazonaws.mobileconnectors.appsync.util.Await} is useful for converting 14 | * async calls to sync. 15 | * 16 | * {@link com.amazonaws.mobileconnectors.appsync.util.Consumer} is a compat version of 17 | * {@link java.util.function.Consumer}, which can be used without worrying about platform 18 | * versions. 19 | * 20 | * {@link com.amazonaws.mobileconnectors.appsync.util.Sleep} is a wrapper around 21 | * {@link java.lang.Thread#sleep(long)}, which reduces the boiler plate of use. 22 | * 23 | * {@link com.amazonaws.mobileconnectors.appsync.util.Wifi} is for turning on/off the 24 | * test device's WiFi. 25 | * 26 | * {@link com.amazonaws.mobileconnectors.appsync.util.JsonExtract} and 27 | * {@link com.amazonaws.mobileconnectors.appsync.util.DataFile} are string/file manipulation 28 | * utilities. 29 | */ 30 | package com.amazonaws.mobileconnectors.appsync.util; 31 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/main/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/aws-android-sdk-appsync-tests/src/main/assets/.gitkeep -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/main/assets/awsconfiguration.json.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/aws-android-sdk-appsync-tests/src/main/assets/awsconfiguration.json.enc -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/main/assets/schema.graphql: -------------------------------------------------------------------------------- 1 | type Comment @model 2 | @key(name: "byEvent", fields: ["eventId", "content", "createdAt"]) { 3 | eventId: ID! 4 | commentId: String! 5 | content: String! 6 | createdAt: String! 7 | } 8 | 9 | type Event @model { 10 | id: ID! 11 | name: String 12 | where: String 13 | when: String 14 | description: String 15 | comments: [Comment] @connection(keyName: "byEvent", fields: ["id"]) 16 | } 17 | 18 | type Article @model 19 | @versioned 20 | @auth(rules: [ 21 | { allow: public provider: apiKey }, 22 | { allow: private provider: iam} 23 | ]) { 24 | id: ID! 25 | author: String! 26 | title: String 27 | pdf: S3Object 28 | image: S3Object 29 | version: Int! 30 | } 31 | 32 | type S3Object { 33 | bucket: String! 34 | key: String! 35 | region: String! 36 | localUri: String 37 | mimeType: String 38 | } 39 | 40 | type Post @model #(subscriptions: { level: public }) 41 | @auth(rules: [ 42 | { allow: private provider: userPools }, 43 | { allow: private provider: iam}, 44 | { allow: public provider: apiKey } 45 | ]){ 46 | id: ID! 47 | author: String! 48 | title: String 49 | content: String 50 | url: String 51 | ups: Int 52 | downs: Int 53 | version: Int! 54 | } 55 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/main/res/raw/awsconfiguration.json: -------------------------------------------------------------------------------- 1 | { 2 | "UserAgent": "aws-amplify-cli/0.1.0", 3 | "Version": "1.0", 4 | "IdentityManager": { 5 | "Default": {} 6 | }, 7 | "AppSync": { 8 | "Default": { 9 | "ApiUrl": "https://xyz.appsync-api.us-east-2.amazonaws.com/graphql", 10 | "Region": "us-east-2", 11 | "AuthMode": "API_KEY", 12 | "ApiKey": "da2-api-key", 13 | "ClientDatabasePrefix": "MultiAuthAndroidIntegTestApp_API_KEY" 14 | }, 15 | "MultiAuthAndroidIntegTestApp_AWS_IAM": { 16 | "ApiUrl": "https://xyz.appsync-api.us-east-2.amazonaws.com/graphql", 17 | "Region": "us-east-2", 18 | "AuthMode": "AWS_IAM", 19 | "ClientDatabasePrefix": "MultiAuthAndroidIntegTestApp_AWS_IAM" 20 | }, 21 | "MultiAuthAndroidIntegTestApp_AMAZON_COGNITO_USER_POOLS": { 22 | "ApiUrl": "https://xyz.appsync-api.us-east-2.amazonaws.com/graphql", 23 | "Region": "us-east-2", 24 | "AuthMode": "AMAZON_COGNITO_USER_POOLS", 25 | "ClientDatabasePrefix": "MultiAuthAndroidIntegTestApp_AMAZON_COGNITO_USER_POOLS" 26 | }, 27 | "MultiAuthAndroidIntegTestApp_AMAZON_COGNITO_USER_POOLS_2": { 28 | "ApiUrl": "https://xyz.appsync-api.us-east-2.amazonaws.com/graphql", 29 | "Region": "us-east-2", 30 | "AuthMode": "AMAZON_COGNITO_USER_POOLS", 31 | "ClientDatabasePrefix": "MultiAuthAndroidIntegTestApp_AMAZON_COGNITO_USER_POOLS_2" 32 | }, 33 | "MultiAuthAndroidIntegTestApp_NoClientDatabasePrefix": { 34 | "ApiUrl": "https://xyz.appsync-api.us-east-2.amazonaws.com/graphql", 35 | "Region": "us-east-2", 36 | "AuthMode": "API_KEY", 37 | "ApiKey": "da2-api-key" 38 | } 39 | }, 40 | "CredentialsProvider": { 41 | "CognitoIdentity": { 42 | "Default": { 43 | "PoolId": "", 44 | "Region": "us-east-1" 45 | } 46 | } 47 | }, 48 | "CognitoUserPool": { 49 | "Default": { 50 | "PoolId": "", 51 | "AppClientId": "", 52 | "AppClientSecret": "", 53 | "Region": "us-east-1" 54 | }, 55 | "Custom": { 56 | "PoolId": "", 57 | "AppClientId": "", 58 | "AppClientSecret": "", 59 | "Region": "us-east-1" 60 | } 61 | }, 62 | "S3TransferUtility": { 63 | "Default": { 64 | "Bucket": "", 65 | "Region": "us-east-1" 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync-tests/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | aws-android-sdk-appsync-tests 3 | 4 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | appsync_test_credentials.json 3 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=aws-android-sdk-appsync 2 | POM_NAME=AWS Android SDK - AppSync GraphQL 3 | POM_DESCRIPTION=AWS SDK for Android - AppSync GraphQL client library 4 | POM_PACKAGING=aar 5 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/proguard-rules.pro: -------------------------------------------------------------------------------- 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 22 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/aws-android-sdk-appsync/src/main/assets/.gitkeep -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/AWSAppSyncAppLifecycleObserver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import androidx.lifecycle.Lifecycle; 11 | import androidx.lifecycle.LifecycleObserver; 12 | import androidx.lifecycle.OnLifecycleEvent; 13 | import android.util.Log; 14 | 15 | public class AWSAppSyncAppLifecycleObserver implements LifecycleObserver { 16 | //Constant for Logging 17 | private static final String TAG = AWSAppSyncDeltaSync.class.getSimpleName(); 18 | 19 | @OnLifecycleEvent(Lifecycle.Event.ON_START) 20 | public void startSomething() { 21 | Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Delta Sync: App is in FOREGROUND"); 22 | AWSAppSyncDeltaSync.handleAppForeground(); 23 | } 24 | 25 | @OnLifecycleEvent(Lifecycle.Event.ON_STOP) 26 | public void stopSomething() { 27 | Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Delta Sync: App is in BACKGROUND"); 28 | AWSAppSyncDeltaSync.handleAppBackground(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/AWSAppSyncClientException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | /** 11 | * Checked Exception thrown by AWSAppSyncClient. 12 | */ 13 | public class AWSAppSyncClientException extends Exception { 14 | /** 15 | * Default constructor. 16 | */ 17 | public AWSAppSyncClientException() { 18 | super(); 19 | } 20 | 21 | /** 22 | * @param message the exception message. 23 | */ 24 | public AWSAppSyncClientException(final String message) { 25 | super(message); 26 | } 27 | 28 | /** 29 | * @param message the exception message. 30 | * @param cause the throwable object that contains the cause. 31 | */ 32 | public AWSAppSyncClientException(final String message, final Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | /** 37 | * @param cause the throwable object that contains the cause 38 | */ 39 | public AWSAppSyncClientException(final Throwable cause) { 40 | super(cause); 41 | } 42 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/AWSAppSyncDeltaSyncSqlHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | 9 | package com.amazonaws.mobileconnectors.appsync; 10 | 11 | import android.content.Context; 12 | import android.database.sqlite.SQLiteDatabase; 13 | import android.database.sqlite.SQLiteOpenHelper; 14 | 15 | /* 16 | Delta Sync Database Helper 17 | */ 18 | class AWSAppSyncDeltaSyncSqlHelper extends SQLiteOpenHelper { 19 | 20 | public static final String TABLE_DELTA_SYNC = "delta_sync"; 21 | public static final String COLUMN_ID = "_id"; 22 | public static final String COLUMN_DELTA_SYNC_KEY = "delta_sync_key"; 23 | public static final String COLUMN_LAST_RUN_TIME = "last_run_time"; 24 | 25 | private static final String DATABASE_NAME = "appsync_deltasync_db"; 26 | private static final int DATABASE_VERSION = 1; 27 | 28 | //Database Create Statement 29 | private static final String DATABASE_CREATE = String.format( 30 | "create table %s( %s integer primary key autoincrement, %s text not null, %s Integer);", 31 | TABLE_DELTA_SYNC, 32 | COLUMN_ID, 33 | COLUMN_DELTA_SYNC_KEY, 34 | COLUMN_LAST_RUN_TIME); 35 | 36 | 37 | //Constructor 38 | public AWSAppSyncDeltaSyncSqlHelper(Context context) { 39 | super(context, DATABASE_NAME, null, DATABASE_VERSION); 40 | } 41 | 42 | //Constructor 43 | public AWSAppSyncDeltaSyncSqlHelper(Context context, String databaseName) { 44 | super(context, databaseName, null, DATABASE_VERSION); 45 | } 46 | 47 | 48 | @Override 49 | /* 50 | Create the database 51 | */ 52 | public void onCreate(SQLiteDatabase database) { 53 | database.execSQL(DATABASE_CREATE); 54 | } 55 | 56 | @Override 57 | /* 58 | Drop the table 59 | */ 60 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 61 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_DELTA_SYNC); 62 | onCreate(db); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/AppSyncMutationQueueInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import com.apollographql.apollo.interceptor.ApolloInterceptor; 11 | import com.apollographql.apollo.interceptor.ApolloInterceptorChain; 12 | 13 | import java.util.Map; 14 | import java.util.concurrent.Executor; 15 | 16 | import javax.annotation.Nonnull; 17 | 18 | /** 19 | * AppSyncMutationQueueInterceptor. 20 | */ 21 | 22 | public class AppSyncMutationQueueInterceptor implements ApolloInterceptor { 23 | 24 | Map mutationMap; 25 | 26 | public AppSyncMutationQueueInterceptor(Map mutationMap) { 27 | this.mutationMap = mutationMap; 28 | } 29 | 30 | @Override 31 | public void interceptAsync(@Nonnull InterceptorRequest request, @Nonnull ApolloInterceptorChain chain, @Nonnull Executor dispatcher, @Nonnull CallBack callBack) { 32 | if(mutationMap.containsKey(request.operation.operationId())) { 33 | // already in map 34 | } 35 | } 36 | 37 | @Override 38 | public void dispose() { 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/AppSyncOptimisticUpdateInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import android.util.Log; 11 | 12 | import com.apollographql.apollo.api.Operation; 13 | import com.apollographql.apollo.cache.normalized.ApolloStore; 14 | import com.apollographql.apollo.interceptor.ApolloInterceptor; 15 | import com.apollographql.apollo.interceptor.ApolloInterceptorChain; 16 | 17 | import java.util.concurrent.Executor; 18 | 19 | import javax.annotation.Nonnull; 20 | 21 | /** 22 | * AppSyncOptimisticUpdateInterceptor. 23 | */ 24 | 25 | class AppSyncOptimisticUpdateInterceptor implements ApolloInterceptor { 26 | private static final String TAG = AppSyncOptimisticUpdateInterceptor.class.getSimpleName(); 27 | private ApolloStore store; 28 | 29 | public void setStore(ApolloStore store) { 30 | this.store = store; 31 | } 32 | 33 | @Override 34 | public void interceptAsync(@Nonnull final InterceptorRequest request, 35 | @Nonnull ApolloInterceptorChain chain, 36 | @Nonnull Executor dispatcher, 37 | @Nonnull CallBack callBack) { 38 | if (request.optimisticUpdates.isPresent()) { 39 | final Operation.Data data = request.optimisticUpdates.get(); 40 | dispatcher.execute(new Runnable() { 41 | @Override 42 | public void run() { 43 | try { 44 | Log.v(TAG,"Thread:[" + Thread.currentThread().getId() +"]: Updating store with the optimistic update for [" + request.operation +"]"); 45 | store.write(request.operation, data).execute(); 46 | } catch (Exception e) { 47 | Log.e(TAG, "Thread:[" + Thread.currentThread().getId() +"]: failed to update store with optimistic update for: [" + request.operation +"]"); 48 | } 49 | } 50 | }); 51 | } 52 | chain.proceedAsync(request, dispatcher, callBack); 53 | } 54 | 55 | @Override 56 | public void dispose() { 57 | // do nothing 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/ClearCacheException.java: -------------------------------------------------------------------------------- 1 | package com.amazonaws.mobileconnectors.appsync; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Exception thrown by AWSAppSyncClient#clearCaches() when there 8 | * is an error thrown during the clear caches operation. 9 | */ 10 | public class ClearCacheException extends AWSAppSyncClientException { 11 | /** 12 | * Default constructor. 13 | */ 14 | public ClearCacheException() { 15 | super(); 16 | } 17 | 18 | /** 19 | * @param message the exception message. 20 | */ 21 | public ClearCacheException(final String message) { 22 | super(message); 23 | } 24 | 25 | /** 26 | * @param message the exception message. 27 | * @param cause the throwable object that contains the cause. 28 | */ 29 | public ClearCacheException(final String message, final Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | /** 34 | * @param cause the throwable object that contains the cause 35 | */ 36 | public ClearCacheException(final Throwable cause) { 37 | super(cause); 38 | } 39 | 40 | private List exceptions; 41 | 42 | public List getExceptions() { 43 | return exceptions; 44 | } 45 | 46 | public void addException(Exception exception) { 47 | if (exceptions == null) { 48 | exceptions = new ArrayList(); 49 | } 50 | exceptions.add(exception); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/ConflictMutation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import javax.annotation.Nonnull; 11 | 12 | /** 13 | * ConflictMutation. 14 | */ 15 | 16 | public class ConflictMutation { 17 | final String mutationId; 18 | final int retryCount; 19 | 20 | public ConflictMutation(@Nonnull String mutationId, @Nonnull int retryCount) { 21 | this.mutationId = mutationId; 22 | this.retryCount = retryCount; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/ConflictResolutionFailedException.java: -------------------------------------------------------------------------------- 1 | package com.amazonaws.mobileconnectors.appsync; 2 | 3 | import com.apollographql.apollo.exception.ApolloException; 4 | 5 | public class ConflictResolutionFailedException extends ApolloException { 6 | public ConflictResolutionFailedException(String message) { 7 | super(message); 8 | } 9 | 10 | public ConflictResolutionFailedException(String message, Throwable cause) { 11 | super(message, cause); 12 | } 13 | 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/ConflictResolverInterface.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import org.json.JSONObject; 11 | 12 | import javax.annotation.Nonnull; 13 | 14 | /** 15 | * ConflictResolverInterface. 16 | */ 17 | 18 | public interface ConflictResolverInterface { 19 | 20 | public void resolveConflict(@Nonnull ConflictResolutionHandler handler, 21 | @Nonnull JSONObject serverState, 22 | @Nonnull JSONObject clientState, 23 | @Nonnull String recordIdentifier, 24 | @Nonnull String operationType); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/DomainType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import java.util.regex.Matcher; 11 | import java.util.regex.Pattern; 12 | 13 | /** 14 | * The type of domain specified in API endpoint. 15 | */ 16 | enum DomainType { 17 | /** 18 | * Standard domain type composed of AWS AppSync endpoint where unique-id is made of 26 alphanumeric characters. 19 | * See AppSync Endpoints 20 | */ 21 | STANDARD, 22 | 23 | /** 24 | * Custom domain defined by the user. 25 | */ 26 | CUSTOM; 27 | 28 | private static final String STANDARD_ENDPOINT_REGEX = 29 | "^https://\\w{26}\\.appsync-api\\.\\w{2}(?:(?:-\\w{2,})+)-\\d\\.amazonaws.com/graphql$"; 30 | 31 | /** 32 | * Get Domain type based on defined endpoint. 33 | * @param endpoint Endpoint defined in config. 34 | * @return {@link DomainType} based on supplied endpoint. 35 | */ 36 | static DomainType from(String endpoint) { 37 | if (isRegexMatch(endpoint)) { 38 | return STANDARD; 39 | } 40 | 41 | return CUSTOM; 42 | } 43 | 44 | private static boolean isRegexMatch(String endpoint) { 45 | final Pattern pattern = Pattern.compile(DomainType.STANDARD_ENDPOINT_REGEX, Pattern.CASE_INSENSITIVE); 46 | final Matcher matcher = pattern.matcher(endpoint); 47 | 48 | return matcher.matches(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/InMemoryOfflineMutationObject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import android.os.Handler; 11 | import android.os.HandlerThread; 12 | import android.os.Message; 13 | import android.util.Log; 14 | 15 | import com.apollographql.apollo.interceptor.ApolloInterceptor; 16 | import com.apollographql.apollo.interceptor.ApolloInterceptorChain; 17 | 18 | import java.util.concurrent.Executor; 19 | 20 | import javax.annotation.Nonnull; 21 | 22 | import static com.amazonaws.mobileconnectors.appsync.AppSyncOfflineMutationManager.MSG_EXEC; 23 | 24 | /** 25 | * InMemoryOfflineMutationObject. 26 | */ 27 | 28 | class InMemoryOfflineMutationObject { 29 | 30 | final String recordIdentifier; 31 | final ApolloInterceptor.InterceptorRequest request; 32 | final ApolloInterceptorChain chain; 33 | final Executor dispatcher; 34 | final ApolloInterceptor.CallBack callBack; 35 | private static final String TAG = InMemoryOfflineMutationObject.class.getSimpleName(); 36 | 37 | public InMemoryOfflineMutationObject(String recordIdentifier, 38 | @Nonnull ApolloInterceptor.InterceptorRequest request, 39 | @Nonnull ApolloInterceptorChain chain, 40 | @Nonnull Executor dispatcher, 41 | @Nonnull ApolloInterceptor.CallBack callBack) { 42 | this.recordIdentifier = recordIdentifier; 43 | this.request = request; 44 | this.chain = chain; 45 | this.dispatcher = dispatcher; 46 | this.callBack = callBack; 47 | } 48 | 49 | public void execute( ) { 50 | // execute the originalMutation by proceeding with the chain. 51 | Log.v(TAG, "Thread:[" + Thread.currentThread().getId() +"]: Executing mutation by proceeding with the chain."); 52 | chain.proceedAsync(request, dispatcher, callBack); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/MessageNumberUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | /** 11 | * MessageNumberUtil. 12 | */ 13 | 14 | public class MessageNumberUtil { 15 | public static final int MSG_EXEC = 100; 16 | public static final int MSG_CHECK = 200; 17 | public static final int MSG_DISCONNECT = 300; 18 | public static final int SUCCESSFUL_EXEC = 400; 19 | public static final int FAIL_EXEC = 500; 20 | public static final int RETRY_EXEC = 600; 21 | } 22 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/MutationInfoUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import com.apollographql.apollo.api.Mutation; 11 | import com.apollographql.apollo.interceptor.ApolloInterceptor; 12 | 13 | enum MuationType { 14 | InMemory, 15 | Persistent 16 | } 17 | 18 | /** 19 | * MutationInformation. 20 | */ 21 | class MutationInformation { 22 | InMemoryOfflineMutationObject originalInMemoryMutation; 23 | PersistentOfflineMutationObject originalPersistMutation; 24 | String clientState; 25 | ApolloInterceptor.CallBack customerCallBack; 26 | Mutation retryMutation; 27 | MuationType muationType; 28 | String uniqueIdentifier; 29 | 30 | public MutationInformation(String uniqueIdentifier, 31 | InMemoryOfflineMutationObject originalInMemoryMutation, 32 | ApolloInterceptor.CallBack customerCallBack, 33 | String clientState) { 34 | this.originalInMemoryMutation = originalInMemoryMutation; 35 | this.customerCallBack = customerCallBack; 36 | this.clientState = clientState; 37 | this.muationType = MuationType.InMemory; 38 | this.uniqueIdentifier = uniqueIdentifier; 39 | } 40 | 41 | public MutationInformation(String uniqueIdentifier, 42 | PersistentOfflineMutationObject persistentOfflineMutationObject, 43 | String clientState) { 44 | 45 | this.uniqueIdentifier = uniqueIdentifier; 46 | this.originalPersistMutation = persistentOfflineMutationObject; 47 | this.clientState = clientState; 48 | this.muationType = MuationType.Persistent; 49 | } 50 | 51 | void updateRetryMutation(Mutation retryMutation) { 52 | this.retryMutation = retryMutation; 53 | } 54 | 55 | void updateCustomerCallBack(ApolloInterceptor.CallBack customerCallBack) { 56 | this.customerCallBack = customerCallBack; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/PersistentMutationsCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | /** 11 | * PersistentMutationsCallback. 12 | */ 13 | 14 | public interface PersistentMutationsCallback { 15 | 16 | void onResponse(PersistentMutationsResponse response); 17 | 18 | void onFailure(PersistentMutationsError error); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/PersistentMutationsError.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import javax.annotation.Nonnull; 11 | 12 | /** 13 | * PersistentMutationsError. 14 | */ 15 | 16 | public class PersistentMutationsError { 17 | private Exception exception; 18 | private String mutationClassName; 19 | private String recordIdentifier; 20 | 21 | public PersistentMutationsError(@Nonnull String mutationClassName, @Nonnull String recordIdentifier, @Nonnull Exception exception) { 22 | this.exception = exception; 23 | this.mutationClassName = mutationClassName; 24 | this.recordIdentifier = recordIdentifier; 25 | } 26 | 27 | public Exception getException() { 28 | return this.exception; 29 | } 30 | 31 | public String getMutationClassName() { 32 | return this.mutationClassName; 33 | } 34 | 35 | public String getRecordIdentifier() { 36 | return this.recordIdentifier; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/PersistentMutationsResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import org.json.JSONArray; 11 | import org.json.JSONObject; 12 | 13 | /** 14 | * PersistentMutationsResponse. 15 | */ 16 | 17 | public class PersistentMutationsResponse { 18 | private JSONObject data; 19 | private JSONArray errors; 20 | private String mutationClassName; 21 | private String recordIdentifier; 22 | 23 | public PersistentMutationsResponse(JSONObject data, JSONArray errors, String mutationClassName, String recordIdentifier) { 24 | this.data = data; 25 | this.errors = errors; 26 | this.mutationClassName = mutationClassName; 27 | this.recordIdentifier = recordIdentifier; 28 | } 29 | 30 | public JSONObject getDataJSONObject() { 31 | return this.data; 32 | } 33 | 34 | public JSONArray getErrorsJSONObject() { 35 | return this.errors; 36 | } 37 | 38 | public String getMutationClassName() { 39 | return this.mutationClassName; 40 | } 41 | 42 | public String getRecordIdentifier() { 43 | return this.recordIdentifier; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/PersistentOfflineMutationObject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | /** 11 | * PersistentOfflineMutationObject. 12 | */ 13 | 14 | public class PersistentOfflineMutationObject { 15 | final String recordIdentifier; 16 | final String requestString; 17 | final String responseClassName; 18 | final String clientState; 19 | final String bucket; 20 | final String key; 21 | final String region; 22 | final String localURI; 23 | final String mimeType; 24 | 25 | public PersistentOfflineMutationObject(final String recordIdentifier, 26 | final String requestString, 27 | final String responseClassName, 28 | final String clientState) { 29 | this(recordIdentifier, 30 | requestString, 31 | responseClassName, 32 | clientState, 33 | null, 34 | null, 35 | null, 36 | null, 37 | null); 38 | } 39 | 40 | public PersistentOfflineMutationObject(final String recordIdentifier, 41 | final String requestString, 42 | final String responseClassName, 43 | final String clientState, 44 | final String bucket, 45 | final String key, 46 | final String region, 47 | final String localURI, 48 | final String mimeType) { 49 | this.recordIdentifier = recordIdentifier; 50 | this.requestString = requestString; 51 | this.responseClassName = responseClassName; 52 | this.clientState = clientState; 53 | this.bucket = bucket; 54 | this.key = key; 55 | this.region = region; 56 | this.localURI = localURI; 57 | this.mimeType = mimeType; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/sigv4/APIKeyAuthProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.sigv4; 9 | 10 | public interface APIKeyAuthProvider { 11 | public String getAPIKey(); 12 | } 13 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/sigv4/AWSLambdaAuthProvider.java: -------------------------------------------------------------------------------- 1 | package com.amazonaws.mobileconnectors.appsync.sigv4; 2 | 3 | public interface AWSLambdaAuthProvider { 4 | public String getLatestAuthToken(); 5 | } 6 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/sigv4/BasicAPIKeyAuthProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.sigv4; 9 | 10 | import android.util.Log; 11 | 12 | import com.amazonaws.mobile.config.AWSConfiguration; 13 | 14 | public class BasicAPIKeyAuthProvider implements APIKeyAuthProvider { 15 | private final String apiKey; 16 | 17 | private static final String TAG = BasicAPIKeyAuthProvider.class.getSimpleName(); 18 | 19 | public BasicAPIKeyAuthProvider(String apiKey) { 20 | this.apiKey = apiKey; 21 | } 22 | 23 | /** 24 | * Read the ApiKey from AppSync section of the awsconfiguration.json file. 25 | * 26 | *

27 | * "AppSync": { 28 | * "Default": { 29 | * "ApiUrl": "https://xxxxxxxxxxxxxxxx.appsync-api..amazonaws.com/graphql", 30 | * "Region": "us-east-1", 31 | * "ApiKey": "da2-yyyyyyyyyyyyyyyy", 32 | * "AuthMode": "API_KEY" 33 | * } 34 | * } 35 | *

36 | * 37 | *

38 | * AWSConfiguration awsConfiguration = new AWSConfiguration(getApplicationContext(); 39 | * APIKeyAuthProvider apiKeyAuthProvider = new BasicAPIKeyAuthProvider(awsConfiguration); 40 | *

41 | * 42 | * @param awsConfiguration The object representing the configuration 43 | * information from awsconfiguration.json 44 | */ 45 | public BasicAPIKeyAuthProvider(AWSConfiguration awsConfiguration) { 46 | try { 47 | this.apiKey = awsConfiguration.optJsonObject("AppSync").getString("ApiKey"); 48 | } catch (Exception exception) { 49 | Log.e(TAG, "Please check the ApiKey passed from awsconfiguration.json."); 50 | throw new RuntimeException("Please check the ApiKey passed from awsconfiguration.json.", exception); 51 | } 52 | } 53 | 54 | @Override 55 | public String getAPIKey() { 56 | return apiKey; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/sigv4/CognitoUserPoolsAuthProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.sigv4; 9 | 10 | public interface CognitoUserPoolsAuthProvider { 11 | public String getLatestAuthToken(); 12 | } 13 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/sigv4/OidcAuthProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.sigv4; 9 | 10 | public interface OidcAuthProvider { 11 | public String getLatestAuthToken(); 12 | } 13 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/subscription/AppSyncSubscription.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.subscription; 9 | 10 | import android.util.Log; 11 | 12 | import com.apollographql.apollo.api.Subscription; 13 | import com.apollographql.apollo.internal.response.OperationResponseParser; 14 | 15 | import java.util.List; 16 | 17 | import okio.BufferedSource; 18 | 19 | public class AppSyncSubscription { 20 | Subscription call; 21 | OperationResponseParser parser; 22 | 23 | private AppSyncSubscription(Builder builder) { 24 | call = builder.call; 25 | parser = createMessageParser(call); 26 | } 27 | 28 | private OperationResponseParser createMessageParser(Subscription call) { 29 | return new OperationResponseParser( 30 | call, 31 | null,//responseFieldMapper, 32 | null,//scalarTypeAdapters, 33 | null); 34 | } 35 | 36 | public void parse(BufferedSource source) { 37 | try { 38 | this.parser.parse(source); 39 | } catch (Exception e) { 40 | Log.w("TAG", "Failed to parse subscription", e); 41 | } 42 | } 43 | 44 | public static Builder builder() { 45 | return new Builder(); 46 | } 47 | 48 | public static class Builder { 49 | Subscription call; 50 | List topics; 51 | 52 | protected Builder() { 53 | 54 | } 55 | 56 | public Builder call(Subscription call) { 57 | this.call = call; 58 | return this; 59 | } 60 | 61 | public Builder topics(List topics) { 62 | this.topics = topics; 63 | return this; 64 | } 65 | 66 | public AppSyncSubscription build() { 67 | return new AppSyncSubscription(this); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/subscription/SubscriptionCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.subscription; 9 | 10 | public interface SubscriptionCallback { 11 | void onMessage(String topic, String message); 12 | 13 | void onError(String topic, Exception e); 14 | } 15 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/subscription/SubscriptionClient.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.subscription; 9 | 10 | import java.util.Set; 11 | 12 | public interface SubscriptionClient { 13 | void connect(SubscriptionClientCallback callback); 14 | void subscribe(String topic, int qos, SubscriptionCallback callback); 15 | void unsubscribe(String topic); 16 | void setTransmitting(boolean isTransmitting); 17 | public Set getTopics(); 18 | void close(); 19 | } 20 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/subscription/SubscriptionClientCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.subscription; 9 | 10 | public interface SubscriptionClientCallback { 11 | void onConnect(); 12 | void onError(Exception e); 13 | } 14 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/subscription/SubscriptionDisconnectedException.java: -------------------------------------------------------------------------------- 1 | package com.amazonaws.mobileconnectors.appsync.subscription; 2 | 3 | /** 4 | Indicates if a subscription was disconnected. 5 | */ 6 | public class SubscriptionDisconnectedException extends Exception { 7 | 8 | public SubscriptionDisconnectedException(String message) { 9 | super(message); 10 | } 11 | 12 | public SubscriptionDisconnectedException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/subscription/SubscriptionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.subscription; 9 | 10 | public interface SubscriptionListener { 11 | void onMessage(T message); 12 | void onError(Exception e); 13 | } 14 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync.utils; 9 | 10 | import okio.Buffer; 11 | 12 | public class StringUtils { 13 | public static String toHumanReadableAscii(String s) { 14 | for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) { 15 | c = s.codePointAt(i); 16 | if (c > '\u001f' && c < '\u007f') continue; 17 | 18 | Buffer buffer = new Buffer(); 19 | buffer.writeUtf8(s, 0, i); 20 | for (int j = i; j < length; j += Character.charCount(c)) { 21 | c = s.codePointAt(j); 22 | if (c > '\u001f' && c < '\u007f') { 23 | buffer.writeUtf8CodePoint(c); 24 | } 25 | } 26 | return buffer.readUtf8(); 27 | } 28 | return s; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/main/java/com/apollographql/apollo/cache/normalized/sql/SqlNormalizedCacheFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2019 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.apollographql.apollo.cache.normalized.sql; 9 | 10 | import com.amazonaws.mobileconnectors.appsync.cache.normalized.sql.AppSyncSqlHelper; 11 | import com.apollographql.apollo.cache.normalized.NormalizedCacheFactory; 12 | import com.apollographql.apollo.cache.normalized.RecordFieldJsonAdapter; 13 | 14 | import static com.apollographql.apollo.api.internal.Utils.checkNotNull; 15 | 16 | public final class SqlNormalizedCacheFactory extends NormalizedCacheFactory { 17 | private final AppSyncSqlHelper helper; 18 | 19 | public SqlNormalizedCacheFactory(AppSyncSqlHelper helper) { 20 | this.helper = checkNotNull(helper, "helper == null"); 21 | } 22 | 23 | @Override 24 | public SqlNormalizedCache create(RecordFieldJsonAdapter recordFieldAdapter) { 25 | return new SqlNormalizedCache(recordFieldAdapter, helper); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/test/java/com/amazonaws/mobileconnectors/appsync/DomainTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Amazon.com, 3 | * Inc. or its affiliates. All Rights Reserved. 4 | *

5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | package com.amazonaws.mobileconnectors.appsync; 9 | 10 | import org.junit.Assert; 11 | import org.junit.Test; 12 | 13 | public class DomainTypeTest { 14 | private static final String STANDARD_URL = 15 | "https://abcdefghijklmnopqrstuvwxyz.appsync-api.us-west-2.amazonaws.com/graphql"; 16 | private static final String CUSTOM_URL = "https://something.in.somedomain.com/graphql"; 17 | 18 | /** 19 | * Test that Domain type is {@link DomainType#STANDARD} for generated URL. 20 | */ 21 | @Test 22 | public void testStandardURLMatch() { 23 | Assert.assertEquals(DomainType.STANDARD, DomainType.from(STANDARD_URL)); 24 | } 25 | 26 | /** 27 | * Test that Domain type is set to {@link DomainType#CUSTOM} for custom URLs. 28 | */ 29 | @Test 30 | public void testCustomURLMatch() { 31 | Assert.assertEquals(DomainType.CUSTOM, DomainType.from(CUSTOM_URL)); 32 | } 33 | } -------------------------------------------------------------------------------- /aws-android-sdk-appsync/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker: -------------------------------------------------------------------------------- 1 | mock-maker-inline -------------------------------------------------------------------------------- /build-support/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem "fastlane" 4 | gem "addressable", ">= 2.8.0" 5 | gem "rexml", ">= 3.3.6" 6 | 7 | plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') 8 | eval_gemfile(plugins_path) if File.exist?(plugins_path) 9 | -------------------------------------------------------------------------------- /build-support/fastlane/Appfile: -------------------------------------------------------------------------------- 1 | json_key_file("") # Path to the json secret file - Follow https://docs.fastlane.tools/actions/supply/#setup to get one 2 | package_name("com.amazonaws") # e.g. com.krausefx.app 3 | -------------------------------------------------------------------------------- /build-support/fastlane/Fastfile: -------------------------------------------------------------------------------- 1 | default_platform(:android) 2 | 3 | import_from_git( 4 | url: 'https://github.com/aws-amplify/amplify-ci-support', 5 | branch: 'android/fastlane-actions', 6 | path: './src/fastlane/release_actions/fastlane/AndroidAppsFastfile' 7 | ) 8 | 9 | # When testing against local changes, comment out the above and use the line below instead. 10 | # import '~/github/aws-amplify/amplify-ci-support/src/fastlane/release_actions/fastlane/AndroidAppsFastfile' 11 | 12 | platform :android do |options| 13 | override_lane :build_parameters do 14 | project_root = File.expand_path("#{Dir.pwd()}/../..") 15 | { 16 | repo: 'awslabs/aws-mobile-appsync-sdk-android', 17 | product_name: 'AWS AppSync SDK for Android', 18 | releases: [ 19 | { 20 | release_tag_prefix: 'release_v', 21 | gradle_properties_path: "#{project_root}/gradle.properties", 22 | doc_files_to_update: [], 23 | release_title: 'AWS AppSync SDK for Android', 24 | changelog_path: "#{project_root}/CHANGELOG.md", 25 | } 26 | ] 27 | } 28 | end 29 | end -------------------------------------------------------------------------------- /build-support/fastlane/Pluginfile: -------------------------------------------------------------------------------- 1 | # Autogenerated by fastlane 2 | # 3 | # Ensure this file is checked in to source control! 4 | 5 | gem 'fastlane-plugin-release_actions', git: 'https://github.com/aws-amplify/amplify-ci-support', branch: 'android/fastlane-actions', glob: 'src/fastlane/release_actions/*.gemspec' 6 | gem 'fastlane-plugin-semantic_release' 7 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.3.61' 3 | ext.aws_version = AWS_CORE_SDK_VERSION 4 | 5 | repositories { 6 | maven { 7 | url "https://plugins.gradle.org/m2/" 8 | } 9 | google() 10 | mavenCentral() 11 | } 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:3.5.3' 14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 15 | classpath "com.amazonaws:aws-android-sdk-appsync-gradle-plugin:3.1.3" 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | maven { 22 | url "https://plugins.gradle.org/m2/" 23 | } 24 | google() 25 | mavenCentral() 26 | } 27 | } 28 | 29 | subprojects { project -> 30 | afterEvaluate { 31 | if (System.getenv("ORG_GRADLE_PROJECT_signingKeyId") != null) { 32 | System.out.println("Getting signing info from protected source.") 33 | project.ext.'signing.keyId' = System.getenv("ORG_GRADLE_PROJECT_signingKeyId") 34 | project.ext.'signing.password' = System.getenv('ORG_GRADLE_PROJECT_signingPassword') 35 | project.ext.'signing.inMemoryKey' = System.getenv('ORG_GRADLE_PROJECT_signingInMemoryKey') 36 | project.ext.SONATYPE_NEXUS_USERNAME = System.getenv('ORG_GRADLE_PROJECT_SONATYPE_NEXUS_USERNAME') 37 | project.ext.SONATYPE_NEXUS_PASSWORD = System.getenv('ORG_GRADLE_PROJECT_SONATYPE_NEXUS_PASSWORD') 38 | } 39 | } 40 | } 41 | 42 | task clean(type: Delete) { 43 | delete rootProject.buildDir 44 | } 45 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | org.gradle.parallel=true 14 | 15 | GROUP=com.amazonaws 16 | VERSION_NAME=3.4.2 17 | AWS_CORE_SDK_VERSION=2.22.1 18 | 19 | POM_URL=https://github.com/awslabs/aws-mobile-appsync-sdk-android 20 | POM_SCM_URL=https://github.com/awslabs/aws-mobile-appsync-sdk-android 21 | POM_SCM_CONNECTION=scm:git:git://github.com/awslabs/aws-mobile-appsync-sdk-android.git 22 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/awslabs/aws-mobile-appsync-sdk-android.git 23 | 24 | POM_LICENCE_NAME=Apache License 2.0 25 | POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0 26 | POM_LICENCE_DIST=repo 27 | 28 | POM_DEVELOPER_ID=amazonwebservices 29 | POM_DEVELOPER_ORGANIZATION=Amazon Web Services 30 | POM_DEVELOPER_ORGANIZATION_URL=http://aws.amazon.com 31 | 32 | # AndroidX 33 | android.useAndroidX=true 34 | android.enableJetifier=true 35 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-mobile-appsync-sdk-android/31782227152956abe5b72186187e4b1518a54d3c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 24 15:00:09 PST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | // include ':app' 2 | include ':aws-android-sdk-appsync' 3 | include ':aws-android-sdk-appsync-api' 4 | include ':aws-android-sdk-appsync-compiler' 5 | include ':aws-android-sdk-appsync-gradle-plugin' 6 | include ':aws-android-sdk-appsync-runtime' 7 | //include ':aws-android-sdk-appsync-tests' 8 | --------------------------------------------------------------------------------