Skip to content

Commit

Permalink
created cache command
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissm79 committed Mar 18, 2018
1 parent 940ad8e commit ee3957f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Providers/LighthouseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function register()
});

$this->app->alias('graphql', GraphQL::class);

$this->commands([
\Nuwave\Lighthouse\Support\Console\Commands\CacheCommand::class,
]);
}

/**
Expand Down
45 changes: 45 additions & 0 deletions src/Support/Console/Commands/CacheCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Nuwave\Lighthouse\Support\Console\Commands;

use Illuminate\Console\Command;

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 = 'Cache GraphQL AST.';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (! config('lighthouse.cache')) {
$this->error('The `lighthouse.cache` setting must be set to a file path.');

return;
}

$schema = graphql()->stitcher()->stitch(
config('lighthouse.global_id_field', '_id'),
config('lighthouse.schema.register')
);

graphql()->cache()->set($schema);

$this->info('GraphQL AST successfully cached.');
}
}

0 comments on commit ee3957f

Please sign in to comment.