The AWS AppSync SDK for iOS enables you to access your AWS AppSync backend and perform operations like Queries
, Mutations
, and Subscriptions
. The SDK also includes support for offline operations. This SDK is based off of the Apollo project found here. Please log questions for this client SDK in this repo and questions for the AppSync service in the official AWS AppSync forum.
Note: AWS AppSync uses Swift 4.2. Use Xcode 10.0 or greater to build.
- Consuming through cocoapods:
-
Add the following line to your Podfile:
pod 'AWSAppSync', '~> 2.6.24'
Example:
# Uncomment the next line to define a global platform for your project # platform :ios, '9.0' target 'EventsApp' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! # Pods for EventsApp pod 'AWSAppSync', '~> 2.6.24' end
-
Run
pod install
to install the AppSync SDK -
Now, open the
.xcworkspace
file and import the SDK usingimport AWSAppSync
.
-
Codegen
To use the AppSync SDK, you will need to use
amplify codegen
from the AWS Amplify CLI which helps generate a strongly typed API for your schema. You can find the instructions to use the codegen here: https://aws-amplify.github.io/docs/ios/api
You can find a sample app which uses the AppSync SDK here: https://github.com/aws-samples/aws-mobile-appsync-events-starter-ios
You can find a step by step walk through of setting up codegen backend and accessing it via the iOS client here: https://aws-amplify.github.io/docs/ios/api
Contributing guidelines are noted here.
If you are contributing to the SDK, it is recommended to add some unit/ functional tests and evaluate against existing tests.
-
Unit Tests
Unit Tests do not require any specific setup and can be run directly from your Xcode IDE.
-
Functional Tests
For running functional tests, we will need the following:
- An AppSync API with an
Events App
schema - A Cognito Identity Pool with unauthenticated identities supported
- The Cognito Identity Pool's unauth role should have the
AppSync Invoke Full Access
permission
You can get the backend setup by following the steps below:
- Go to AWS AppSync console.
- Click on
Create New API
and then selectEvent App
and hitCreate
, take a note of theAPI URL
of the created API. - Once the creation completes, select
Settings
from left side of the console and then selectAWS Identity and Access Management (IAM)
as the authorization type. - Next, create a new Cognito Identity Pool and attach
AppSync Invoke Full Access
permission to the unauth role of the Identity Pool. Keep a note of the Identity Pool ID of newly created pool. - Create another AppSync API using the same steps above, but use API Key Auth mode instead which is available by default.
Finally, you will need to setup a config file locally to access the server. Add a file
appsync_test_credentials.json
(see sample below) in theAWSAppSyncTests
folder and replace the values forAppSyncEndpoint
,CognitoIdentityPoolId
,AppSyncEndpointAPIKey
,AppSyncAPIKey
and regions if required:{ "AppSyncEndpoint": "https://asd32hl34523454532.appsync-api.us-east-1.amazonaws.com/graphql", "AppSyncRegion": "us-east-1", "CognitoIdentityPoolId": "us-east-1:abcas234-1234-12324-b4b7-aaa0c0831234", "CognitoIdentityPoolRegion": "us-east-1", "AppSyncEndpointAPIKey": "https://apikeybasedendpoint.appsync-api.us-east-1.amazonaws.com/graphql", "AppSyncEndpointAPIKeyRegion": "us-east-1", "AppSyncAPIKey": "da2-sad3lkh23422" }
Note: The
AppSyncEndpointAPIKey
endpoint usesAPI_KEY
based auth, whileAppSyncEndpoint
uses theAWS_IAM
based auth.Now you should be able to run the functional tests!
- An AppSync API with an
This library is licensed under the Amazon Software License.