PHP code example of mathsgod / r-graphql

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

    

mathsgod / r-graphql example snippets



try {
    $schema = Schema::Build(file_get_contents(__DIR__ . "/schema.gql"), $this->app);
    
} catch (Exception $e) {
    return ["error" => [
        "message" => $e->getMessage()
    ]];
}

$this->request->getBody()->getContents();
$input = json_decode($input, true);
$query = $input['query'];
$variableValues = $input['variables'];

$schema->debug=true;//debug mode

$result = $schema->executeQuery($query, $variableValues);

$this->write(json_encode($result));


try {
    $schema = Schema::Build(file_get_contents(__DIR__ . "/schema.gql"), $this->app);
    $schema->validation($jwt, $key, function ($payload)  {
        print_r($payload);
    });
} catch (Exception $e) {
    return ["error" => [
        "message" => $e->getMessage()
    ]];
}