Skip to content

Instantly share code, notes, and snippets.

@bsilva0x87
Created October 12, 2019 15:35
Show Gist options
  • Save bsilva0x87/02379ec5c6634fd6ce2484bef2f90815 to your computer and use it in GitHub Desktop.
Save bsilva0x87/02379ec5c6634fd6ce2484bef2f90815 to your computer and use it in GitHub Desktop.
Simple implementation for command "lighthouse:print-schema" to compile the final GraphQL schema using Lighthouse / Lumen PHP.
<?php
namespace Nuwave\Lighthouse\Console;
use Nuwave\Lighthouse\GraphQL;
use Illuminate\Console\Command;
use GraphQL\Utils\SchemaPrinter;
class PrintSchemaCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = '
lighthouse:print-schema {--W|write : Write the output to a file}
';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Compile the final GraphQL schema and print the result.';
/**
* Execute the console command.
*
* @param \Nuwave\Lighthouse\GraphQL $graphQL
* @return void
*/
public function handle(GraphQL $graphQL): void
{
$schema = SchemaPrinter::doPrint($graphQL->prepSchema());
file_put_contents('schema.graphql', $schema);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment