PHP code example of bendeckdavid / graphql-client

1. Go to this page and download the library: Download bendeckdavid/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/ */

    

bendeckdavid / graphql-client example snippets


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

GRAPHQL_CREDENTIALS="YOUR_CREDENTIALS"

GRAPHQL_AUTHENTICATION_HEADER="Authorization"

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

use BendeckDavid\GraphqlClient\Facades\GraphQL;

return GraphQL::query('
    capsules {
        id
        original_launch
        status
        missions {
            name
            flight
        }
    }
')->get();
//->get('json'); //get response as json object

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

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

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

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

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

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

return GraphQL::query($query)
->context([
    'ssl' => [
         "verify_peer" => false,
         "verify_peer_name" => false,
    ]
  ])->get();