在 Amplify API 中添加 GraphQL 数据源时遇到授权问题,可能是因为您在创建API时未正确配置API插件,也可能是访问授权密钥的问题。以下是解决此问题的示例代码:
amplify configure api
按照提示进行插件配置,包括创建新API、选择API类型、命名和设置插件。
amplify update api
输入以下内容:
Please select from one of the below mentioned services
GraphQL
REST
Please select the service that you want to update GraphQL
What would you like to do? update
Provide new service name or keep default: (you can default to GraphQL) GraphQL
Choose the default authorization type for the API Amazon Cognito User Pool
Enter a name for your user pool: (your generated new user pool name)
How do you want users to be able to sign in? Username
Do you want to add User Pool Groups? No
Do you want to add an admin queries API? No
Multifactor authentication (MFA) user login options: OFF
Email based user registration/forgot password: Enabled (Requires per-user email id)
Please specify an email verification subject: Your verification code
Please specify an email verification message: Your verification code is {####}
Please specify an email invitation subject [Leave blank for none]:
Please specify an email invitation message [Leave blank for none]:
Do you want to enable any of the following capabilities? (Press
amplify add api
按照提示输入以下内容:
? Please select from one of the below mentioned services GraphQL
? Provide a friendly name for your resource to be used as a label for this category in the project: datasourceName
? Provide the URL of your existing GraphQL API:
在这个过程中,您需要提供正确的访问授权密钥才能成功添加GraphQL数据源。
以上是针对Amplify API添加GraphQL数据源授权问题的解决方法。