{"id":18699121,"url":"https://github.com/ineat/flutter-aws-appsync-sample","last_synced_at":"2025-07-05T15:14:21.493Z","repository":{"id":54868983,"uuid":"139866123","full_name":"ineat/flutter-aws-appsync-sample","owner":"ineat","description":"Create custom bridge for AWS AppSync in Flutter","archived":false,"fork":false,"pushed_at":"2021-01-23T20:30:41.000Z","size":5946,"stargazers_count":117,"open_issues_count":2,"forks_count":28,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-12T08:08:13.538Z","etag":null,"topics":["aws-appsync","bridge","flutter"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ineat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-05T15:08:27.000Z","updated_at":"2024-09-08T15:34:46.000Z","dependencies_parsed_at":"2022-08-14T05:10:54.241Z","dependency_job_id":null,"html_url":"https://github.com/ineat/flutter-aws-appsync-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ineat%2Fflutter-aws-appsync-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ineat%2Fflutter-aws-appsync-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ineat%2Fflutter-aws-appsync-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ineat%2Fflutter-aws-appsync-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ineat","download_url":"https://codeload.github.com/ineat/flutter-aws-appsync-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248537137,"owners_count":21120709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-appsync","bridge","flutter"],"created_at":"2024-11-07T11:31:34.914Z","updated_at":"2025-04-12T08:09:00.306Z","avatar_url":"https://github.com/ineat.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flutter AppSync Demo\n\nCreate custom bridge for AWS AppSync\n\n## Presentation\n\nThis project is an example of using Flutter with the AWS AppSync solution. It is configured in state UE CENTRAL 1 (Francfort)\n\n[![Demo](https://github.com/ineat/flutter-aws-appsync-sample/blob/master/media/demo.gif)](https://github.com/ineat/flutter-aws-appsync-sample/blob/master/media/demo.mp4)\n\nAWS AppSync automatically updates web and mobile application data in real time, and offline user data is updated as soon as it is reconnected.\nIf you use AppSync as a simple GraphQL API without the subscribe feature then it would be better to use the following plugin: : \nhttps://pub.dartlang.org/packages/graphql_flutter\n\n\nThe bridge is based on the official documentation of the AppSync SDK.\n\n**AWS AppSync SDK Android :** \nhttps://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-android.html\n\n**AWS AppSync SDK iOS :** \nhttps://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-ios.html\n\nIf you want more information on the development of a flutter plugin here is an official link: https://flutter.io/developing-packages/\n\nTo make this example work, AppSync is configured with the following GraphQL schema : \n\n\n## GraphQL schema\n\nThe GraphQL schema: \n\n```graphql\ntype Message {\n\tid: ID!\n\tcontent: String!\n\tsender: String!\n}\n\ntype Mutation {\n\tnewMessage(content: String!, sender: String!): Message\n}\n\ntype Query {\n\tgetMessages: [Message]\n}\n\ntype Subscription {\n\tsubscribeToNewMessage: Message\n\t\t@aws_subscribe(mutations: [\"newMessage\"])\n}\n\nschema {\n\tquery: Query\n\tmutation: Mutation\n\tsubscription: Subscription\n}\n```\n\nTo create your GraphQL schema for AppSync, see the link https://docs.aws.amazon.com/appsync/latest/devguide/graphql-overview.html \n\n## Security\n\nAppSync will be secured by API Key.\n\nhttps://docs.aws.amazon.com/appsync/latest/devguide/security.html\n\n## Data Source\n\nThe Data Source used by AppSync is a lambda. Here is this example here is a simplified version :\n\n```javascript\n\nvar incrementId = 0;\nvar messages = [];\n\nexports.handler = async (event, context, callback) =\u003e {\n    switch (event.field) {\n        // match with Data Template resolver\n        case 'getMessages':\n            getMessages(event, context, callback);\n            break;\n        case 'newMessage':\n            newMessage(event, context, callback);\n            break;\n        default: throw new Error(\"unsupported\");\n    }\n};\n\nfunction getMessages(event, context, callback) {\n    callback(null, messages);\n}\n\nasync function newMessage(event, context, callback) {\n    const args = event.arguments;\n    const msg = {\n        id: (++incrementId).toString(),\n        content: args.content,\n        sender: args.sender,\n        conversationId: args.conversationId\n    };\n    messages.push(msg);\n    \n    callback(null, msg);\n}\n```\n\nTo link the GraphQL schema methods to the lambda refer to the following link : https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html\n\n## Resolvers\n\nRequest template resolver for NewMessage Mutation :\n\n```javascript\n{\n    \"version\" : \"2017-02-28\",\n    \"operation\": \"Invoke\",\n    \"payload\": {\n    \t\"field\" : \"newMessage\",\n        \"arguments\": $util.toJson($context.args)\n    }\n}\n```\n\nRequest template resolver for GetMessages Query :\n\n```javascript\n{\n    \"version\" : \"2017-02-28\",\n    \"operation\": \"Invoke\",\n    \"payload\": {\n    \t\"field\" : \"getMessages\",\n        \"arguments\": $util.toJson($context.args)\n    }\n}\n```\n\n## Configuration sample\n\nTo configure AppSync in the project, modify the constants of the file /lib/constants.dart\n\n```dart\nconst AWS_APP_SYNC_ENDPOINT = \"YOUR ENDPOINT\"; // like https://xxx.appsync-api.eu-central-1.amazonaws.com/graphql\nconst AWS_APP_SYNC_KEY = \"YOUR API KEY\";\n```\n\n# Custom Configuration in your project\n\n## 1. Android\n\n**_Step 1:_** add aws android SDK classpath\n\n\n```groovy\n// android/build.gradle\nbuildscript {\n\n    dependencies {\n        classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.6.17'\n    }\n\n}\n\n```\n\n_**Step 2:**_ Plugin plugin and SDK\n\n```groovy\n// android/app/build.gradle\n\napply plugin: 'com.amazonaws.appsync'\n\ndependencies {\n    implementation 'com.amazonaws:aws-android-sdk-appsync:2.6.17'\n    implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'\n    implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'\n    implementation 'com.android.support:support-v4:27.1.1'\n}\n```\n\n_**Step 3:**_ add schema and request GraphQL\n\nCopy your files in :\n\n/android/app/src/main/graphql/your.package.name/*.graphql\n/android/app/src/main/graphql/your.package.name/*.json\n\n\n_**Step 4:**_ Configure Android Manifest\n\n```xml\n\n\u003cmanifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"com.ineat.appsync\"\u003e\n\n\n    \u003cuses-permission android:name=\"android.permission.INTERNET\"/\u003e\n    \u003cuses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.WAKE_LOCK\" /\u003e\n    \n    \u003capplication\u003e\n        \u003c!-- ... --\u003e\n        \u003c!-- Service paho for retrieve all data in background --\u003e\n        \u003cservice android:name=\"org.eclipse.paho.android.service.MqttService\" /\u003e\n    \u003c/application\u003e\n    \n\u003c/manifest\u003e\n```\n\n_**Step 5:**_ Generation GraphQL models\n\nLaunch gradle command : \n\n```shell\n# /android\n./gradle generateApolloClasses\n```\n\n## 2. iOS\n\n_**Step 1:**_ add AWS SDK in your Podfile\n\n```ruby\ntarget 'Runner' do\n  use_frameworks!\n  pod 'AWSAppSync', '~\u003e 2.6.7'\nend\n```\n\n_**Step 2:**_ Retrieve all dependencies\n\n```ruby\npod install\n```\n\n_Caution:_ Configure your deployment target at 9.0 (Runner.xcworkspace)\n\n_**Step 3:**_ add schema and request GraphQL\n\nCopy your files in :\n\n/iOS/*.graphql\n/iOS/schema.json\n\n\nFor generate models you have to use the npm library aws-appsync-codegen (https://www.npmjs.com/package/aws-appsync-codegen)\n\nLaunch the command :\n\n```shell\n# ios/\naws-appsync-codegen generate *.graphql --schema schema.json --output ./Runner/AppSyncAPI.swift\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fineat%2Fflutter-aws-appsync-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fineat%2Fflutter-aws-appsync-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fineat%2Fflutter-aws-appsync-sample/lists"}