0

I am having an issue running a mutation that was generated by the Amplify CLI.
I'm on node v14.18.1, amplify CLI 7.6.2.

I just recently migrated to the GraphQL Transformer v2.

Here is my model:

type User
  @model
  @auth(
    rules: [
      { allow: groups, groups: ["admin"] }
      { allow: owner, ownerField: "id", operations: [read] }
    ]
  ) {
  id: ID! 
  first_name: String
  last_name: String
  email: String!
  customer: Customer @hasOne(fields: ["userCustomerId"])
  userCustomerId: ID! @index(name: "usersByCreatedAt", queryField: "usersByCreatedAt" sortKeyFields: ["createdAt"])
  createdAt: String!
  isAdmin: Boolean
}

The mutation I'm calling from within AppSync:

mutation UpdateUser {
  updateUser(input: {id: "asdfasdfasdf", isAdmin: true, last_name: "Franklin", first_name: "Tim", email: "tim@tim.com", userCustomerId: "my_customer"}) {
    id
  }
}

Error:

{
  "data": {
    "updateUser": null
  },
  "errors": [
    {
      "path": [
        "updateUser"
      ],
      "data": null,
      "errorType": "MappingTemplate",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "Unsupported element '$[operation]'."
    }
  ]
}

Has anyone ran into this error, and how did you resolve it? Thank you!

Tim
  • 344
  • 1
  • 12

2 Answers2

3

Check what "Data Source" your resolver function is connected to. You can see this information in the AppSync web UI for the given resolver function. If the Data Source is not mapped to the correct place or if it's set to NONE_DS, then all of the operations for the given resolver function will fail.

This error happened to me when I accidentally connected the resolver to the RDS datasource instead of the DynamoDB one.

gxc
  • 4,946
  • 6
  • 37
  • 55
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 26 '22 at 08:21
2

Check if there are any .vtl files in project_dir/amplify/backend/api/api_name/resolvers. If there are and you're not sure why/don't recognize them, back up and delete those files, deploy your local backend with amplify push, and see if the mutation succeeds.

I was getting the exact same error during a delete mutation and this resolved it for me. The Amplify CLI auto-generates templates for the API service, but overrides them with any it finds in that directory. Just make sure to back up all of those files before deleting them just in case..

formula-hunter
  • 121
  • 1
  • 5