omnilance / graphql-php-client
一个简单的客户端,用于在GraphQL中执行查询和突变
0.0.5
2017-06-22 13:14 UTC
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~5.0
This package is not auto-updated.
Last update: 2024-09-29 01:56:55 UTC
README
一个简单的客户端,用于在GraphQL中执行查询和突变
安装
composer require omnilance/graphql-php-client
或 composer require "omnilance/graphql-php-client": ">=0.0.3"
简单用法
use Omnilance\GraphQL\Client;
$client = new Client($api_token);
另外,您可以设置自定义主机
$client->setHost($host);
运行查询
$query = '{
domain_check(domain: "rx-name.net" {
cost,
avail
}
}';
$response = $client->response($query);
$query = '{
allDomains(first:10) {
domain {
id,
name,
register_date,
expired_date,
}
}
}';
$response = $client->response($query);
foreach($response->allDomains->domain as $domain) {
print $domain->name;
}
响应类
all()
使用 $response->all();
获取响应中返回的所有数据
errors()
使用 $response->errors();
获取响应中返回的所有错误
hasErrors()
使用 $response->hasErrors();
检查响应中是否包含任何错误