Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Commit 46ff4e8

Browse files
authored
Enable route caching by adding a dedicated controller (#11)
Without this PR this package adds a route with an anonymous controller function. This is incompatible with native Laravel route caching, causing the following exception: ```bash $ php artisan route:cache Route cache cleared! LogicException : Unable to prepare route [graphql-playground] for serialization. Uses Closure. at /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php:880 876| */ 877| public function prepareForSerialization() 878| { 879| if ($this->action['uses'] instanceof Closure) { > 880| throw new LogicException("Unable to prepare route [{$this->uri}] for serialization. Uses Closure."); 881| } 882| 883| $this->compileRoute(); 884| Exception trace: 1 Illuminate\Routing\Route::prepareForSerialization() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/RouteCacheCommand.php:62 2 Illuminate\Foundation\Console\RouteCacheCommand::handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29 Please use the argument -v to see more details. ``` With this PR route caching is possible again by introducing a controller class for the playground.
2 parents 7bc24ba + 1dbaa54 commit 46ff4e8

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/GraphQLPlaygroundController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace MLL\GraphQLPlayground;
4+
5+
use Illuminate\Routing\Controller;
6+
7+
class GraphQLPlaygroundController extends Controller
8+
{
9+
public function get()
10+
{
11+
return view('graphql-playground::index');
12+
}
13+
}

src/GraphQLPlaygroundServiceProvider.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ public function boot()
3030
return;
3131
}
3232

33-
\Route::get(config('graphql-playground.route'), [
34-
'middleware' => config('graphql-playground.middleware', ''),
35-
'as' => 'graphql-playgroundcontroller',
36-
'uses' => function () {
37-
return view('graphql-playground::index');
38-
},
39-
]);
33+
\Route::get(
34+
config('graphql-playground.route'),
35+
GraphQLPlaygroundController::class . '@get'
36+
)->middleware(
37+
config('graphql-playground.middleware')
38+
);
4039
}
4140

4241
/**

0 commit comments

Comments
 (0)