Skip to content

alexaandrov/laravel-graphql-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Laravel GraphQL Client

Wrapper over euautomation/graphql-client library for laravel/lumen.

Installation

You can install the package via composer:

composer require alexaandrov/laravel-graphql-client

Set endpoint url in your .env

GRAPHQL_ENDPOINT_URL=https://your-endpoint.url

For laravel:

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

For lumen:

Copy and setting up config:

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

Add to bootstrap/app.php

$app->configure('graphql-client');
$app->register(Alexaandrov\GraphQL\GraphQLClientServiceProvider::class);

Usage

Code

<?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->...;

About

๐Ÿš€ GraphQL client for laravel/lumen

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages