简体   繁体   English

AWS Amplify:如何使用 API_KEY 进行测试和开发

[英]AWS Amplify: how to use API_KEY for test and development purpose

I am using amplify for my project.我正在为我的项目使用放大。 I have enabled both cognito and API_KEY authorization and added following function to use instead of 'graphqlOperation' of amplify-cli我启用了 cognito 和 API_KEY 授权,并添加了以下函数来代替 amplify-cli 的“graphqlOperation”

function graphqlOperationWithAPIKey(query, variables) {
    return {query: query, variables: variables, authMode: 'API_KEY'}
}

And I doing the call:我打电话:

const response = await API.graphql(graphqlOperationWithAPIKey(mutations.createContract, {input: mockContract}))

However I am getting the following error:但是我收到以下错误:

Failed: Object {
  "data": Object {
    "createContract": null,
  },
  "errors": Array [
    Object {
      "data": [Object],
      "errorInfo": [Object],
      "errorType": "Unauthorized",
      "locations": [Array],
      "message": "Not Authorized to access createContract on type Mutation",
      "path": [Array],
    },
  ],
}

Here is my schema:这是我的架构:

type Contract @model {
  id: ID!    
  rental: Car @connection

  from: AWSDate!
  to: AWSDate!
  tenants: [String!]! 
  status: ContractStatus!
}

Can someone help me to get this work?有人可以帮我完成这项工作吗?

I don't know whether is bug or not, the below works if I add it to schema, but @aws_key doe not work (even according to doc should work as well)我不知道是否是错误,如果我将它添加到架构,下面的工作,但 @aws_key 不起作用(即使根据 doc 也应该工作)

@auth (
  rules: [
    { allow: public, provider: apiKey }
  ]
) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM