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
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)
@auth (
rules: [
{ allow: public, provider: apiKey }
]
)