Closed26

Amplify 経由で既存の AppSync 環境を使う[Android]

tkttkt

新しく作成したものでやるやり方は書いてあるけど、既存のものに繋ぐやり方は全然書いてなくて困った

tkttkt
# amplify status
You are not working inside a valid Amplify project.
Use 'amplify init' in the root of your app directory to initialize your project, or 'amplify pull' to pull down an existing project.

これも動かない

# amplify pull

しても変わりなし

既存リソースを触る場合はこの辺りは使わないのかもしれない

tkttkt
# amplify pull

For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

? Do you want to use an AWS profile? Yes
? Please choose the profile you want to use default
? Which app are you working on? d2wd9ycvjuafbk
Backend environment 'dev' found. Initializing...
? Choose your default editor: IntelliJ IDEA
? Choose the type of app that you're building android
Please tell us about your project
? Where is your Res directory:  app/src/main/res
? Do you plan on modifying this backend? No

Added backend environment config object to your project.
Run 'amplify pull' to sync upstream changes.
? Do you plan on modifying this backend? Yes
⠦ Fetching updates to backend environment: dev from the cloud.Could not initialize 'dev': Stack with id amplify-appsyncsample-dev-XXXXX does not exist
tkttkt

aws console から schema.graphql をとってきて、プロジェクトルートにおいた

tkttkt
# amplify add codegen --apiId f3t52j6zobcujczh5wdswymmuu
? Choose the type of app that you're building android
? Enter the file name pattern of graphql queries, mutations and subscriptions app/src/main/graphql/**/*.graphql
? Do you want to generate/update all possible GraphQL operations - queries, mutations and subscriptions Yes
? Enter maximum statement depth [increase from default if your schema is deeply nested] 2
✔ Generated GraphQL operations successfully and saved at app/src/main/graphql/com/amazonaws/amplify/generated/graphql

生成に成功

tkttkt

いつの間にか amplifyconfiguration.json が消えてた
もろもろ再度試してみる

tkttkt

追加し直したけど、apikey の直書きしちゃまずい
json まるごと ignore したほうがいいのか…?

tkttkt

amplifyconfiguration.json 再追加した後に amplify pull しても特に変わりなし

tkttkt

appsync 環境を作ってるだけであれば、amplify の環境は新規作成しないといけない…?

tkttkt

amplify init から始めてみる

tkttkt

amplify add codegen --apiId xxxxxxxxxxxxxxxxxxxx
も成功

tkttkt
# amplify codegen models                             
No AppSync API configured. Please add an API
# amplify add api
? Please select from one of the below mentioned services: GraphQL
You already have an AppSync API in your project. Use the "amplify update api" command to update your existing AppSync API.
? Provide API name: (android)

新しいところに進んだ

tkttkt
# amplify update api
? Please select from one of the below mentioned services: GraphQL
The selected resource is not managed using AWS Cloudformation. Please use the AWS AppSync Console to make updates to your API - GraphqlAPI
Error: The selected resource is not managed using AWS Cloudformation. Please use the AWS AppSync Console to make updates to your API - GraphqlAPI
    at exports.updateWalkthrough (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-api/lib/provider-utils/awscloudformation/service-walkthroughs/appSync-walkthrough.js:224:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Object.executeAmplifyCommand (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-api/lib/index.js:166:5)
    at async executePluginModuleCommand (/usr/local/lib/node_modules/@aws-amplify/cli/lib/execution-manager.js:166:5)
    at async Object.executeCommand (/usr/local/lib/node_modules/@aws-amplify/cli/lib/execution-manager.js:35:9)
    at async Object.run (/usr/local/lib/node_modules/@aws-amplify/cli/lib/index.js:91:9)

cloudformation 使って構築したんだけど…

tkttkt

既存リソースとか全部置いておいて、素直に最初から構築してみることにする

tkttkt

向き先変えて
できるかやってみようかな

tkttkt

もう一度最初から構築してみる

tkttkt
# amplify status

Current Environment: dev

| Category | Resource name | Operation | Provider plugin |
| -------- | ------------- | --------- | --------------- |

この状態からどうやってモデル生成まで持っていくか

tkttkt

amplify 使わずに普通の sdk から appsync いじるのが王道なんかな

このスクラップは2020/12/23にクローズされました