PHP code example of alexaandrov / laravel-graphql-client

1. Go to this page and download the library: Download alexaandrov/laravel-graphql-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alexaandrov / laravel-graphql-client example snippets




$guery = <<<QUERY
query {
    users {
        id
        email
    }
}
QUERY;

$mutation = <<<MUTATION
mutation {
    login(data: {
        username: "[email protected]"
        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->...;

php artisan vendor:publish --provider="Alexaandrov\GraphQL\GraphQLClientServiceProvider" 

cp vendor/alexaandrov/laravel-graphql-client/config/config.php config/graphql-client.php