PHP code example of x-graphql / codegen

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

    

x-graphql / codegen example snippets

 


return [
    'default' => [
        /// PSR 4 namespace, classes and traits generated will use.
        'namespace' => 'App\GraphQL\Codegen',
        /// Where storing GraphQL queries files.
        'sourcePath' => __DIR__ . '/',
        /// Where storing PHP generated code with namespace above.
        'destinationPath' => __DIR__ . '/',
        /// Generated query class name.
        'queryClassName' => 'GraphQLQuery',
    ]
];



gator = new \XGraphQL\HttpSchema\HttpDelegator('https://countries.trevorblades.com/');
$schema = \XGraphQL\HttpSchema\HttpSchemaFactory::createFromIntrospectionQuery($delegator);
$query = new \App\GraphQL\Codegen\GraphQLQuery($schema);

$result = $query->getCountries();

var_dump($result->toArray());