Это функция cURL, которая может отправлять или получать данные. Он должен работать с любым PHP-приложением, поддерживающим OAuth:
function jwt_request($url,$token, $post) {
header('Content-Type: application/json'); // Specify the type of data
$ch = curl_init($url); // Initialise cURL
$post = json_encode($post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1); // Specify the request method as POS
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); // Set the posted fields
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // This will follow any redirects
$result = curl_exec($ch); // Execute the cURL statement
curl_close($ch); // Close the cURL connection
return ($result); // Return the received data
}
// I am running in localhost
$url = "http://localhost:3000/graphql";
// This is what query i am running
$post = '{"query": "query { login(username:"[email protected]",password: "abbas") { userID token } }" }';
// This is the function i am using in above
$json = jwt_request($url,$token, $post);
echo "<pre>";
print_r($json); // here printing






Потратив столько времени и усилий, я нашел лучшее решение для этой проблемы — просто использовать этот репозиторий git с помощью композитора, и он отлично работает, но вы должны иметь некоторые знания о композиторе и о том, как установить и использовать его. библиотеки с помощью автозагрузки полезного файла.
Вот ссылка на репозиторий. Они уже привели правильный пример с использованием провайдера OAuth2.
Надеюсь, поможет.
Вот пример кода:
<?php
$client = \Softonic\GraphQL\ClientBuilder::build('https://catalog.swarm.pub.softonic.one/graphql');
$query = <<<'QUERY'
query GetFooBar($idFoo: String, $idBar: String) {
foo(id: $idFoo) {
id_foo
bar (id: $idBar) {
id_bar
}
}
}
QUERY;
$variables = [
'idFoo' => 'foo',
'idBar' => 'bar',
];
$response = $client->query($query, $variables);
?>