Create mutation with dynamic variables / React

Hi guys, first of all I apologize as I’m french so my english isn’t the best.
Secondly I’ve search for a long time for an answer but couldn’t find anything.

Anyway, I’m trying to create new data to my strapi backend with react.

To do so I created a Collection Type called “Test” with a single “name” field in it.

In react I first tried to create a new field with this query

mutation {
createTest(input:
{data : {
name: “myNewTest”
}}) {
test {
name
}
}
}

And it work just fine.

Now I would like to make the “name” field dynamic like if you define it with an input for exemple.

And I’m stuck here. I’ve tried multiple solution like =>

const CREATE_TEST = gqlmutation CreateTest($input: CreateTestInput!) { createTest(input: {data: {$input}}) { test {name}} }

and then I call this query using apollo useMutation like so =>

const [createTest] = useMutation(CREATE_TEST, {
    variables: { name: name }
})

And no matter what I do I keep getting an error status code 404.

Please help !

Solved.

Here is the solution =>

Query =>

const CREATE_TEST = gql`
mutation CreateTest($input: createTestInput) {
  createTest(input: $input) {
    test {
      name
    }
  }
}
`

Variables =>

const myTestName = "mario"

const [createTest] = useMutation(CREATE_TEST, {
    variables: {
        "input": {
            "data": {
                "name": myTestName,
            }
        }
    }
})