New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

alexaandrov/laravel-graphql-client

GraphQL client for laravel/lumen
6,491 12
Install
composer require alexaandrov/laravel-graphql-client
Latest Version:0.2.0
PHP:>= 7.1
License:MIT
Last Updated:Aug 15, 2019
Links: GitHub  ·  Packagist
Maintainer: alexaandrov

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

Related Packages

nuwave/lighthouse

A framework for serving GraphQL from Laravel

13,623,862 3,497
vdhicts/hihaho-api-client

A client for the API of HiHaHo

18,383 0
secundo/laravel-graphql-query-builder

A powerful and elegant GraphQL query builder for PHP, designed specifically for...

17,654 3
cline/relay

A modern, attribute-driven HTTP client for PHP

10,803 0

Version History

Version Released PHP License
0.2.0 >= 7.1 MIT
0.1.1 >= 7.1 MIT
0.1.0 >= 7.1 MIT
0.0.2 >= 7.1 MIT
0.0.1 >= 7.1 MIT