Skip to content

Commit

Permalink
Merge pull request #2 from xaviered/ecalle/custom_namespace_codegen
Browse files Browse the repository at this point in the history
Using custom namespace for codegen files, and updating tests
  • Loading branch information
xaviered authored Jun 24, 2021
2 parents 46a70fe + fa52e18 commit ae7445c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bin/generate_schema_objects
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if (!$autoLoadFound) {

use GraphQL\Client;
use gmostafa\GraphQL\SchemaGenerator\SchemaClassGenerator;
use gmostafa\GraphQL\SchemaGenerator\CodeGenerator\ObjectBuilderInterface;

$endpointUrl = readline('GraphlQL endpoint URL: ');

Expand All @@ -31,8 +32,12 @@ if (!empty($authHeaderName)) {
$customWriteDir = readline('Custom classes writing dir (optional): ');
if (empty($customWriteDir)) $customWriteDir = '';

$defaultNamespace = ObjectBuilderInterface::DEFAULT_NAMESPACE;
$customNamespace = readline('Custom namespace prefix (default: ' . ObjectBuilderInterface::DEFAULT_NAMESPACE . '): ');
if (empty($customNamespace)) $customNamespace = ObjectBuilderInterface::DEFAULT_NAMESPACE;

$client = new Client($endpointUrl, $authHeaders);
$scanner = new SchemaClassGenerator($client, $customWriteDir);
$scanner = new SchemaClassGenerator($client, $customWriteDir, $customNamespace);

print "-------------------------------------------\n";
print "Generating schema objects from schema types\n";
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
},
"autoload-dev": {
"psr-4": {
"GraphQL\\Tests\\": "tests/"
"gmostafa\\GraphQL\\Tests\\": "tests/",
"testing\\GraphQL\\SchemaObject\\": "schema_object/"
}
},
"bin": ["bin/generate_schema_objects"],
"scripts": {
"test": "./vendor/bin/phpunit tests"
},
"require": {
"php": "^7.1 || ^8.0",
"gmostafa/php-graphql-client": "^1.6 || ^1.9"
Expand Down
34 changes: 34 additions & 0 deletions examples/ping_query_example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

/**
* Testing custom namespace codegen.
*
* 1) Start your GraphQL server with the `ping` query.
* For more info on running your own GraphQL server, see https://www.apollographql.com/
*
* 2) Run the following command and make sure to use `testing\GraphQL\SchemaObject` as the custom namespace:
* $ php bin/generate_schema_objects
*
* 3) Update composer maps
* $ composer dump-autoload
*
* 4) Run this command:
* $ php examples/ping_query_example.php
*
* You should see the output of the returned query.
*/

require_once __DIR__ . '/../vendor/autoload.php';

use testing\GraphQL\SchemaObject\RootQueryObject;
use GraphQL\Client;

const API_URL = 'http://localhost:8080/';
$client = new Client(API_URL);

$root = new RootQueryObject();
$root->selectPing();

$result = $client->runQuery($root->getQuery());

print_r(['r' => $result]);

0 comments on commit ae7445c

Please sign in to comment.