xpromx / laravel-graphql-client by xpromx

GraphQL Client For Laravel
373
6
2
Package Data
Maintainer Username: xpromx
Maintainer Contact: xpromx@gmail.com (xpromx)
Package Create Date: 2017-08-31
Package Last Update: 2022-12-22
Home Page:
Language: PHP
License: Unknown
Last Refreshed: 2024-11-23 03:03:17
Package Statistics
Total Downloads: 373
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 6
Total Watchers: 2
Total Forks: 2
Total Open Issues: 2

Installation

You can install this package via composer using this command:

composer require travelience/laravel-graphql-client

Or add in your composer.json

   "require": {
        "travelience/laravel-graphql-client": "dev-master"
   },

Service Provider

Travelience\GraphQL\GraphQLServiceProvider::class,

Config Files

In order to edit the default configuration for this package you may execute:

php artisan vendor:publish

Example


$query = "
        { users{id,name,email} }
        ";

$r = GraphQL::query( $query );

// check if the response has errors
if( $r->hasErrors() )
{
    // return a string of the first error messasge
    dd($r->getErrorMessage());

    // return a laravel collection with the errors
    dd($r->errors());
}

// will return laravel collection
dd( $r->get('users') );
dd( $r->users );

Query params


/**
* @param  string  $query : { users{id, name, email} }
* @param  array  $params : extra parameters in the POST
* @param  integer $cache : in minutes
* @return Response
*/
$r = GraphQL::query( $query, $params=[], $cache=false );