alexaandrov / laravel-graphql-client
laravel/lumen 的 GraphQL 客户端
0.2.0
2019-08-15 10:20 UTC
Requires
- php: >= 7.1
- ext-json: *
- euautomation/graphql-client: ^0.2.0
README
laravel/lumen 的 euautomation/graphql-client 库的包装器。
安装
您可以通过 composer 安装此包
composer require alexaandrov/laravel-graphql-client
在 .env 中设置端点 URL
GRAPHQL_ENDPOINT_URL=https://your-endpoint.url
对于 Laravel
php artisan vendor:publish --provider="Alexaandrov\GraphQL\GraphQLClientServiceProvider"
对于 Lumen
复制并设置配置
cp vendor/alexaandrov/laravel-graphql-client/config/config.php config/graphql-client.php
添加到 bootstrap/app.php
$app->configure('graphql-client');
$app->register(Alexaandrov\GraphQL\GraphQLClientServiceProvider::class);
用法
代码
<?php $guery = <<<QUERY query { users { id email } } QUERY; $mutation = <<<MUTATION mutation { login(data: { username: "user@mail.com" password: "qwerty" }) { access_token refresh_token expires_in token_type } } MUTATION; $queryResponse = Alexaandrov\GraphQL\Facades\Client::fetch($query); foreach ($queryResponse->users as $user) { // Do something with the data $user->id; $user->email; } $mutationResponse = Alexaandrov\GraphQL\Facades\Client::fetch($mutation); // Do something with the data $login = $mutationResponse->login; $login->access_token; $login->...;