mathsgod / gql-client
A simple GraphQL client tools for php
3.1.1
2022-05-27 09:08 UTC
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.2
- mathsgod/php-util: ^1.3
Requires (Dev)
- phpunit/phpunit: ^9.5
README
Client example
Query
$client = new GQL\Client($server_address); $data = $client->query([ "me" => [ "first_name", "last_name" ] ]);
With arguments
$client = new GQL\Client($server_address); $data = $client->query([ "getUser" => [ "__args"=>[ "id"=>1 ], "first_name", "last_name", "findInvoice"=>[ "__args"=>[ "status"=>"pending" ], "invoice_no" ] ] ]);
Mutation and Subscription
$data = $client->mutation("updateUser",[ "__args"=>["user_id"=>1,"first_name"=>"Raymond"] ]); $data=$client->subscription("createUser",[ "__args"=>["first_name"=>"raymond"] ]);
auth
$client = new GQL\Client($server_address); $client->auth=["username","password"]; $data = $client->query([ "me" => [ "first_name", "last_name" ] ]);
no ssl check
$client = new GQL\Client($server_address,["verify"=>false]); $data = $client->query([ "me" => [ "first_name", "last_name" ] ]);
Builder
Query
echo Builder::Query([ "me" => [ "first_name", "last_name" ] ]); // query{ me {first_name last_name} }
Mutation
echo Builder:Mutation("updateUser",[ "__args"=>[ "user_id"=>1, "first_name"=>"Raymond" ] ]); // mutation{ updateUser(user_id:1, first_name:"Raymond") }
Subscription
echo Builder:Mutation("createUser",["__args"=>["first_name"=>"Raymond"]]); // subscription{ createUser(first_name:"Raymond") }