Skip to content

Commit

Permalink
Add artisan command lighthouse:cache to compile GraphQL AST (nuwave…
Browse files Browse the repository at this point in the history
  • Loading branch information
tlaverdure committed Jun 25, 2020
1 parent 1b8169d commit bc04164
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
You can find and compare releases at the [GitHub release page](https://github.com/nuwave/lighthouse/releases).

## Unreleased
- Add `php artisan lighthouse:cache` command to compile the AST cache.

## 4.15.0

Expand Down
6 changes: 6 additions & 0 deletions docs/master/api-reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Lighthouse provides some convenient artisan commands. All of them
are namespaced under `lighthouse`.

## cache

Compile the GraphQL AST cache.

php artisan lighthouse:cache

## clear-cache

Clear the cache for the GraphQL AST.
Expand Down
33 changes: 33 additions & 0 deletions src/Console/CacheCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Nuwave\Lighthouse\Console;

use Illuminate\Console\Command;
use Nuwave\Lighthouse\Schema\AST\ASTBuilder;

class CacheCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'lighthouse:cache';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Compile the GraphQL AST cache.';

/**
* Execute the console command.
*/
public function handle(ASTBuilder $builder): void
{
$builder->documentAST();

$this->info('GraphQL AST schema cache created.');
}
}
2 changes: 2 additions & 0 deletions src/LighthouseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Validation\Factory as ValidationFactory;
use Illuminate\Validation\Validator;
use Laravel\Lumen\Application as LumenApplication;
use Nuwave\Lighthouse\Console\CacheCommand;
use Nuwave\Lighthouse\Console\ClearCacheCommand;
use Nuwave\Lighthouse\Console\DirectiveCommand;
use Nuwave\Lighthouse\Console\IdeHelperCommand;
Expand Down Expand Up @@ -164,6 +165,7 @@ public function provideSubscriptionResolver(FieldValue $fieldValue): Closure

if ($this->app->runningInConsole()) {
$this->commands([
CacheCommand::class,
ClearCacheCommand::class,
DirectiveCommand::class,
IdeHelperCommand::class,
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/Console/CacheCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Tests\Unit\Console;

use Nuwave\Lighthouse\Console\CacheCommand;
use Tests\TestCase;

class CacheCommandTest extends TestCase
{
public function testItCachesGraphQLAST(): void
{
$key = config('lighthouse.cache.key');
config(['lighthouse.cache.ttl' => 60]);
$this->commandTester(new CacheCommand)->execute([]);
$this->assertTrue(cache()->has($key));
}
}

0 comments on commit bc04164

Please sign in to comment.