Im using Graphql on remote server and php+curl on main server, when im tryin go update or creat new im got an error "Unexpected token ** in JSON at position"
I'm really trying to shielding but is is doesn't help. If im made request from graphql frontend it is works fine.
Fine JSON request:
mutation {
updateMarket(Id: "002384fa-7d45-e911-9c76-00155d056158", Lat: 122, Lng: 1) {
Id
Lat
}
}
Php code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '192.168.1.1:4040/graphql');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "mutation {\n updateMarket(Id: \"002384fa-7d45-e911-9c76-00155d056158\", Lat: 122, Lng: 1) {\n Id\n Lat\n }\n}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
2 Answers
After some times of research Im find a lib "gmostafa/php-graphql-client" (composer require) It is nice instrument for make querys and mutation for Graphql API from php.
It's not correct JSON syntax. What do you want from this "mutation" row?