Minimal GraphQL client for Laravel.

Overview

Minimal GraphQL Laravel Client

Minimal GraphQL client for Laravel.

Requirements

  • Composer 2+

Installation

Install Package (Composer 2+)

composer require bendeckdavid/graphql-client

Usage

Enviroment variable

GRAPHQL_ENDPOINT="https://api.spacex.land/graphql/"

Authentication

We provide a minimal authentication integration by appending the Authorization header to the request client. You can pass the credentials using an env variable.

GRAPHQL_CREDENTIALS="YOUR_CREDENTIALS"

You can also pass auth credentials at runtime using withToken($credentials) method.

'Authorization' header and 'Bearer' Schema are used by default. You can override the default behaviour by defining following variables in your .env file.

GRAPHQL_AUTHENTICATION_HEADER="Authorization"

// Allowed: basic, bearer, custom
GRAPHQL_AUTHENTICATION="bearer"

Usage/Examples

Import GraphQL Client Facades

use BendeckDavid\GraphqlClient\Facades\GraphQL;

Basic use

return GraphQL::query('
    capsules {
        id
        original_launch
        status
        missions {
            name
            flight
        }
    }
')->get()

Mutator request:

get()">
return GraphQL::mutator('
    insert_user(name: "David") {
        id
        name
        date_added
    }
')->get()

You can access "query" or "mutator" as a shortcut if you are not passing variables, if is not the case you must use the "raw" attribute:

"David"]) ->get()">
return GraphQL::raw('
    mutation($name: String) {
        insert_user(name: $name) {
            id
            name
            date_added
        }
    }
')
->with(["name" => "David"])
->get()

The variables or payload to the GraphQL request can also be passed using magic methods like:

get() ">
return GraphQL::raw('
    mutation($name: String) {
        insert_user(name: $name) {
            id
            name
            date_added
        }
    }
')
->withName("David")
->get()

If you want to address te request to another endpoint, you can do :

query(' capsules { id original_launch status missions { name flight } } ')->get() ">
return GraphQL::endpoint("https://api.spacex.land/graphql/")
->query('
    capsules {
        id
        original_launch
        status
        missions {
            name
            flight
        }
    }
')->get()

Headers

You can include a header to the request by using the attribute "header" or add multiple headers by "withHeaders":

return GraphQL::query($query)
->header('name', 'value')
->withHeaders([
    'name' => 'value',
    'name' => 'value'
])->get();

Author

Top Contributors

Contributors

Contributions are always welcome!

Comments
  • Code is php 8 compatible only won't run on php7.4

    Code is php 8 compatible only won't run on php7.4

    Is your feature request related to a problem? Please describe. First of all great package. Unfortunately it won't run on php7.4. Since the code is full of php 8 only features (constructor property promotion, 'mixed' type hinting in function argument i.e. String|Null or using match() ), you should force php v8 in the composer config file.

    Describe the solution you'd like A perfect solution would be to add php 7.4 compatibility.

    Additional context Global usage based on the packagist stats (https://stitcher.io/blog/php-version-stats-january-2022) still favors 7.x more than 50% of the time over 8.x Most laravel apps written in php7 and already live won't get the php8 upgrade option anytime soon, that's just how production app lifetime is.

    enhancement 
    opened by gm-lunatix 2
  • Setting of properties & attributes using __call()

    Setting of properties & attributes using __call()

    Description

    Added support for setting properties & attributes using magic withPropertyName or withAttributeName methods.

    Type of change

    • [x] New feature (non-breaking change which adds functionality)
    • [x] This change requires a documentation update

    Checklist:

    • [x] My code follows the style guidelines of this project
    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    opened by ehsanquddusi 2
  • How to pass object as variable?

    How to pass object as variable?

    I am having the following query:

    return GraphQL::raw('
    query($filter: LogsFilterInputType) {
        logs(filter: $filter) {
          edges {
            node {
              toAddress
            }
          }
        }
      }
    ')
    ->withFilter($filter)
    ->get();
    

    With the $filter being:

    $filter = '{
        "filter": {
          "type": {
            "eq": "MINT"
          }
        }
      }';
    

    Request always fails with error 400:

    code: "BAD_USER_INPUT",
    "GraphQLError: Variable "$filter" got invalid value "[..]"; Expected type "LogsFilterInputType" to be an object.",
    
    opened by travisbotello 1
  • Add additional context to request

    Add additional context to request

    Description

    Adds additional context to the get_file_content request. My use case involved preventing ssl verify in dev environment.

    Fixes # (issue)

    Type of change

    Please delete options that are not relevant.

    • [x ] New feature (non-breaking change which adds functionality)

    Checklist:

    • [x] My code follows the style guidelines of this project
    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    opened by kerkness 0
  • Feature/with token

    Feature/with token

    • Support to add authorization token using withToken magic method at runtime.
    • Updated documentation to cover with magic methods & passing of auth credentials at runtime using withToken($credentials) method.
    opened by bendeckdavid 0
  • Support for setting auth token at runtime

    Support for setting auth token at runtime

    Description

    Support to add authorisation token using withToken magic method at runtime. This is in addition to the option of setting it in environment.

    Fixes # Useful with oAuth calls, where the access token changes continuously.

    Type of change

    • [x] New feature (non-breaking change which adds functionality)
    • [x] This change requires a documentation update

    Checklist:

    • [x] My code follows the style guidelines of this project
    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    opened by ehsanquddusi 0
  • Feature headers

    Feature headers

    Include Authentication Feature

    .env Variables: GRAPHQL_AUTHENTICATION_HEADER => Define the authorization header, default: 'Authorization' GRAPHQL_CREDENTIALS => Authorization credentials, if this value is null, the authorization header is not included GRAPHQL_AUTHENTICATION => Authorization sheme, default: bearer, options: basic, bearer, custom

    opened by bendeckdavid 0
  • numeric in json, add parameter to get response in json object

    numeric in json, add parameter to get response in json object

    Description

    This pull request come with 1 adjust and 1 new feature

    Type of change

    Please delete options that are not relevant.

    • [ ] New feature (non-breaking change which adds functionality)
    • [ ] This change requires a documentation update

    Checklist:

    • [ ] My code follows the style guidelines of this project
    • [ ] I have performed a self-review of my own code
    • [ ] I have commented my code, particularly in hard-to-understand areas
    • [ ] I have made corresponding changes to the documentation
    opened by chiendv 1
  • Change number in graphql variables to real numeric

    Change number in graphql variables to real numeric

    Hi! I want to make a change to this line and I think will be better if I ask before.

    how about if we change this line: https://github.com/bendeckdavid/graphql-client/blob/46af9f46768a6fb09aeabd854edf961ae5f43df4/src/Classes/Client.php#L57

    to

    'content' => json_encode(['query' => $this->raw_query, 'variables' => $this->variables], JSON_NUMERIC_CHECK),
    

    So the variables:

    $query = ['star'=>[1,2,3]];
    

    send to endpoint will be:

    {"star":[3,4,5]}
    

    instead of

    {"star":["3","4","5"]}
    

    Thank you!

    opened by chiendv 0
Releases(v1.3)
  • v1.3(Jun 21, 2022)

    What's Changed

    • Add additional context to request by @kerkness in https://github.com/bendeckdavid/graphql-client/pull/11

    New Contributors

    • @kerkness made their first contribution in https://github.com/bendeckdavid/graphql-client/pull/11

    Full Changelog: https://github.com/bendeckdavid/graphql-client/compare/v1.2...v1.3

    Source code(tar.gz)
    Source code(zip)
  • v1.2(Jan 6, 2022)

    What's Changed

    • Setting of properties & attributes using __call() by @ehsanquddusi in https://github.com/bendeckdavid/graphql-client/pull/4
    • Support for setting auth token at runtime by @ehsanquddusi in https://github.com/bendeckdavid/graphql-client/pull/5
    • Include magic methods in doc by @ehsanquddusi in https://github.com/bendeckdavid/graphql-client/pull/6

    Full Changelog: https://github.com/bendeckdavid/graphql-client/compare/v1.1...v1.2

    Source code(tar.gz)
    Source code(zip)
  • v1.1(Jan 5, 2022)

    What's Changed

    • Added support for headers by @ehsanquddusi in https://github.com/bendeckdavid/graphql-client/pull/2
    • Feature authentication by @bendeckdavid in https://github.com/bendeckdavid/graphql-client/pull/3

    New Contributors

    • @ehsanquddusi made their first contribution in https://github.com/bendeckdavid/graphql-client/pull/2

    Full Changelog: https://github.com/bendeckdavid/graphql-client/compare/v1.0...v1.1

    Source code(tar.gz)
    Source code(zip)
  • v1.0(Dec 28, 2021)

Owner
David Gutierez Bendeck
David Gutierez Bendeck
A Laravel 8 Project Implement with GraphQL With Sanctum APIs Authentications Which utilized in Any Frontend or Any Mobile Application Programs.

A Laravel 8 Project Implement with GraphQL With Sanctum APIs Authentications Which utilized in Any Frontend or Any Mobile Application Programs.

Vikas Ukani 3 Jan 6, 2022
Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite

Mollie for Laravel Laravel-Mollie incorporates the Mollie API and Mollie Connect into your Laravel or Lumen project. Accepting iDEAL, Apple Pay, Banco

Mollie 289 Nov 24, 2022
A REST client inside your Laravel app

Laravel Compass is an elegant REST assistant for the Laravel framework that you can use to test API calls and create API documentation. it provides automatically endpoints for GET, POST, PUT/PATCH, DELETE, various auth mechanisms, and other utility endpoints based on Laravel routes in your project.

David H. Sianturi 1.2k Dec 31, 2022
Dashboard to view your http client requests in laravel application

Laravel Blanket is a package with wraps laravel http client requests and provide logs for request and response, also give option to retry any request from dashboard and more...

Ahmed waleed 215 Dec 29, 2022
Websockets-Client (Sample) laravel

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Filimantaptius Gulo 1 Mar 8, 2022
This is a laravel 4 package for the server and client side of datatables at http://datatables.net/

Datatable Important This package will not receive any new updates! You can still use this package, but be preparared that there is no active developme

Nils Plaschke 388 Dec 30, 2022
Laravel SES Webhooks Client

Handle AWS SES webhook in Laravel php framework.

Ankur Kumar 16 Oct 26, 2022
Laravel Abdal Detector - Find info about IP , OS and web browser from your client

Laravel Abdal Detector - Find info about IP , OS and web browser from your client

 Abdal Security Group 1 Mar 24, 2022
A OpenID connect client for Laravel framework.

Introduction A OpenID connect client for Laravel framework. Install composer require package/oidc:^1.0 Configuration php artisan vendor:publish --tag=

Betterde 2 Sep 17, 2022
PHP client library for reCAPTCHA, a free service to protect your website from spam and abuse.

reCAPTCHA PHP client library reCAPTCHA is a free CAPTCHA service that protects websites from spam and abuse. This is a PHP library that wraps up the s

Google 3.3k Dec 23, 2022
Shared code for the MaxMind Web Service PHP client APIs

Common Code for MaxMind Web Service Clients This is not intended for direct use by third parties. Rather, it is for shared code between MaxMind's vari

MaxMind 264 Jan 3, 2023
Generator-hedley - Scaffold a headless Drupal backend, Angular app client, and Behat tests

generator-hedley Scaffold a headless Drupal backend, Angular app client, and Behat tests Hedley is a yeoman generator that scaffolds a headless Drupal

null 99 Jun 3, 2022
PHP API for GeoIP2 webservice client and database reader

GeoIP2 PHP API Description This package provides an API for the GeoIP2 and GeoLite2 web services and databases. Install via Composer We recommend inst

MaxMind 2.1k Jan 6, 2023
Hashtopolis is a multi-platform client-server tool for distributing hashcat tasks to multiple computers.

Hashtopolis is a multi-platform client-server tool for distributing hashcat tasks to multiple computers. The main goals for Hashtopolis's development are portability, robustness, multi-user support, and multiple groups management.

Hashtopolis 1.1k Jan 4, 2023
Symfony bundle that provides Cross Site Request Forgery (CSRF or XSRF) protection for client-side applications

CSRF Cookie Bundle This Symfony bundle provides Cross Site Request Forgery (CSRF or XSRF) protection for client-side applications requesting endpoints

David Neustadt 8 Nov 28, 2022
A simple pure PHP RADIUS client supporting Standard and Vendor-Specific Attributes in single file

BlockBox-Radius A simple pure PHP RADIUS client supporting Standard and Vendor-Specific Attributes in single file Author: Daren Yeh [email protected]

null 2 Oct 2, 2022
PHP API for GeoIP2 webservice client and database reader

GeoIP2 PHP API Description This package provides an API for the GeoIP2 and GeoLite2 web services and databases. Install via Composer We recommend inst

MaxMind 2.1k Jan 1, 2023
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

Laravel Lang 6.9k Jan 2, 2023
⚡ Laravel Charts — Build charts using laravel. The laravel adapter for Chartisan.

What is laravel charts? Charts is a Laravel library used to create Charts using Chartisan. Chartisan does already have a PHP adapter. However, this li

Erik C. Forés 31 Dec 18, 2022