How to get the GraphQL mutation params with ctx?

I made a new policy on the update mutation of a collection.

Here is my mutation:

mutation UpdateModel($id: ID!, $name: String) {
  updateWomenModel(input: { where: { id: $id }, data: { name: $name } }) {
    womenModel {
      name
    }
  }
}

I’d like to get access to the id in my policy function. but when I print out ctx.request.body it only gives me what’s inside data

The id in this case is not inside the ctx.body, it is inside the ctx.params.

Take a look here, at the TIP section:
https://strapi.io/documentation/developer-docs/latest/plugins/graphql.html#link-a-query-or-mutation-to-a-controller-action

1 Like