Swift AWS AppSyncをインストールして実装したのでそのメモ
1. 管理画面でスキーマを作成
例えば…
schema { query: Query mutation: Mutation } type Query { getUser(id: ID!): Test getTests: [Test] } type Mutation { addTest(id: ID!, name: String, status: TestStatus): Test } type Test { id: ID! name: String status: TestStatus } enum TestStatus { enabled disabled }
2. schema.jsonをダウンロード
schema.jsonのダウンロードするボタンが画面中のどこかにあるのでそれを押してダウンロード
3. xcodeプロジェクトルートでディレクトリを作成
~/projectName/app/GraphQLOperationsa というディレクトリを作成
中に、以下を作成 test.graphql(テーブルごとにクエリーを作成) schema.json(ダウンロードした内容そのまま) API.swift(空で作成)
※xcodeで作成しないとtreeに表示されないっぽい
4. コマンドを実行
npm install -g aws-appsync-codegen cd ~/projectName/app aws-appsync-codegen generate GraphQLOperations/*.graphql --schema GraphQLOperations/schema.json --output GraphQLOperations/API.swift
5. 一旦build
command + R を実行すると、作成したAPI.swiftがプロジェクトに追加される
6. ロジックを構築する
あとは、以下ドキュメントなどを参考にしながらプロジェクトにあった方法でインスタンス管理をする
https://awslabs.github.io/aws-mobile-appsync-sdk-ios/#update-backend-configuration