I've this mutation that allows me to insert a client inside a collection in MongoDB. when i create the function the php trows a error 500. it's strange for me because it happens when i write the function, and not when i call it
the function is:
function graphQLPost(string $endpoint, string $query, array $variables = [], ?string $token = null)
{
    $payload =  json_encode(['query' => $query, 'variables' => $variables]);
    $headers = array();
    if ($token != null) {
        $headers[] = "Content-Type: application/json\r\n" .
        'Authorization: Bearer ' . $token;
    } else
        $headers[] = 'Content-Type: application/json';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $endpoint);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    // Submit the POST request
    $resultJson = curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    // Close cURL session handle
    curl_close($ch);
    return array($resultJson, $httpcode);
}
// definiamo la mutation
$mutation = '
    mutation createClients($project_id: ID!, $input: ClientInput!) {
    createClients(project_id: $project_id, input: $input) {
      id
      firstName
      lastName
      tel
      email
      trattamento
      profilazione
      marketing
    }
  }  ';
// parametri da passare come argomenti
$param = [
    'project_id' => $PROJECT_ID,
    'input' => array(
        'firstName' => $nome,
        'lastName' => $cognome,
        'email' => $email,
        'tel' => $telefono,
        'trattamento' => $trattamento_DB,
        'profilazione' => $profilazione_DB,
        'marketing' => $marketing_DB,
        'status' => 'lead',
    )
];
// esecuzione del comando
$response = graphQLPost($API_URI, $mutation, $param, $TOKEN);
