diff --git a/CHANGELOG.md b/CHANGELOG.md index a88e5dc1..9ccb5107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ CHANGELOG [Next release](https://github.com/rebing/graphql-laravel/compare/8.6.0...master) -------------- +### Removed +- Remove integrated GraphiQL support in favour of https://github.com/mll-lab/laravel-graphiql [\#986 / mfn](https://github.com/rebing/graphql-laravel/pull/986) 2023-02-18, 8.6.0 ----------------- diff --git a/README.md b/README.md index 74dbc8ef..e6fce2b5 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,6 @@ Review the configuration file: config/graphql.php ``` -The default GraphiQL view makes use of the global `csrf_token()` helper function. - ## Usage - [Laravel GraphQL](#laravel-graphql) @@ -69,7 +67,6 @@ The default GraphiQL view makes use of the global `csrf_token()` helper function - [Concepts](#concepts) - [A word on declaring a field `nonNull`](#a-word-on-declaring-a-field-nonnull) - [Data loading](#data-loading) - - [GraphiQL](#graphiql) - [Middleware Overview](#middleware-overview) - [HTTP middleware](#http-middleware) - [GraphQL execution middleware](#graphql-execution-middleware) @@ -204,20 +201,6 @@ static data, ElasticSearch results, caching, etc.) in your resolvers but you've to be mindful of the execution model to avoid repetitive fetches and perform smart pre-fetching of your data. -### GraphiQL - -GraphiQL is lightweight "GraphQL IDE" in your browser. It takes advantage of the -GraphQL type system and allows autocompletion of all queries/mutations/types and -fields. - -GraphiQL in the meantime evolved in terms of features and complexity, thus for -convenience an older version is directly included with this library. - -As enabled by the default configuration, it's available under the `/graphiql` -route. - -If you are using multiple schemas, you can access them via `/graphiql/`. - ### Middleware Overview The following middleware concepts are supported: @@ -2715,19 +2698,6 @@ To prevent such scenarios, you can add the `UnusedVariablesMiddleware` to your You can define your own pagination type. - `simple_pagination_type`\ You can define your own simple pagination type. -- `graphiql`\ - Config for GraphiQL (see (https://github.com/graphql/graphiql) - - `prefix`\ - The route prefix - - `controller`\ - The controller / method to handle the route - - `middleware`\ - Any middleware to be run before invoking the controller - - `view`\ - Which view to use - - `display`\ - Whether to enable it or not.\ - **Note:** it's recommended to disable this in production! - `defaultFieldResolver`\ Overrides the default field resolver, see http://webonyx.github.io/graphql-php/data-fetching/#default-field-resolver - `headers`\ @@ -2809,7 +2779,7 @@ The following is not a bullet-proof list but should serve as a guide. It's not a - `composer remove folklore/graphql` - if you've a custom ServiceProvider or did include it manually, remove it. The point is that the existing GraphQL code should not be triggered to run. - `composer require rebing/graphql-laravel` -- Publish `config/graphql.php` and adapt it (prefix, middleware, schemas, types, mutations, queries, security settings, graphiql) +- Publish `config/graphql.php` and adapt it (prefix, middleware, schemas, types, mutations, queries, security settings) - Removed settings - `domain` - `resolvers` @@ -2870,4 +2840,4 @@ public function resolve($root, array $args) ## GraphQL testing clients - [Firecamp](https://firecamp.io/graphql) - - [GraphiQL](https://github.com/graphql/graphiql) + - [GraphiQL](https://github.com/graphql/graphiql) [integration via laravel-graphiql](https://github.com/mll-lab/laravel-graphiql) diff --git a/composer.json b/composer.json index 988726e9..c4b9a0be 100644 --- a/composer.json +++ b/composer.json @@ -93,5 +93,8 @@ "config": { "preferred-install": "dist", "sort-packages": true + }, + "suggest": { + "mll-lab/laravel-graphiql": "Easily integrate GraphiQL into your Laravel projects. " } } diff --git a/config/config.php b/config/config.php index 551e9775..24c36f4b 100644 --- a/config/config.php +++ b/config/config.php @@ -157,17 +157,6 @@ */ 'simple_pagination_type' => \Rebing\GraphQL\Support\SimplePaginationType::class, - /* - * Config for GraphiQL (see (https://github.com/graphql/graphiql). - */ - 'graphiql' => [ - 'prefix' => 'graphiql', // Do NOT use a leading slash - 'controller' => \Rebing\GraphQL\GraphQLController::class . '@graphiql', - 'middleware' => [], - 'view' => 'graphql::graphiql', - 'display' => env('ENABLE_GRAPHIQL', true), - ], - /* * Overrides the default field resolver * See http://webonyx.github.io/graphql-php/data-fetching/#default-field-resolver diff --git a/resources/views/README.md b/resources/views/README.md deleted file mode 100644 index 54ad3c5f..00000000 --- a/resources/views/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# GraphiQL integration - -See https://github.com/graphql/graphiql for the home of GraphiQL - -The file `graphiql.php` is an integration of the example provided by GraphiQL. It's a slightly modified version from the official repository so it can be integrated. - -The modifications are documented here in detail as to replicate them on future updates: - -- copy example from packages/graphiql/example/index.html -- adjust CDN URLs from https://cdnjs.com/libraries/graphiql -- graphQLFetcher: replace the hardcoded path with the library configured path: - `return fetch('/graphql', {` => `return fetch('', {` -- csrf integration - - right before `function graphQLFetcher` add: `var xcsrfToken = null;` - - in the actual `fetch` call, add this header: `'x-csrf-token': xcsrfToken || ''` - - in the first `then` after the `fetch` call: `xcsrfToken = response.headers.get('x-csrf-token');` diff --git a/resources/views/graphiql.php b/resources/views/graphiql.php deleted file mode 100644 index 8cc1f294..00000000 --- a/resources/views/graphiql.php +++ /dev/null @@ -1,154 +0,0 @@ - - - - - <?php echo $schema ? "$schema | " : ''; ?>GraphiQL - - - - - - - - - - - - - - -
Loading...
- - - \ No newline at end of file diff --git a/src/Console/PublishCommand.php b/src/Console/PublishCommand.php index 8d25f2ba..bc862a7e 100644 --- a/src/Console/PublishCommand.php +++ b/src/Console/PublishCommand.php @@ -44,7 +44,6 @@ public function __construct(Filesystem $files) $fromPath = __DIR__ . '/../..'; $this->fileMap = [ $fromPath . '/config/config.php' => app()->basePath('config/graphql.php'), - $fromPath . '/resources/views/graphiql.php' => app()->basePath('resources/views/vendor/graphql/graphiql.php'), ]; } diff --git a/src/GraphQLController.php b/src/GraphQLController.php index 756bdf55..62cfc41b 100644 --- a/src/GraphQLController.php +++ b/src/GraphQLController.php @@ -5,8 +5,6 @@ use GraphQL\Server\OperationParams as BaseOperationParams; use Illuminate\Contracts\Config\Repository; -use Illuminate\Contracts\View\Factory; -use Illuminate\Contracts\View\View; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; @@ -48,27 +46,6 @@ function (BaseOperationParams $baseOperationParams) use ($schemaName, $graphql): return response()->json($data, 200, $headers, $jsonOptions); } - public function graphiql(Request $request, Repository $config, Factory $viewFactory): View - { - $routePrefix = $config->get('graphql.graphiql.prefix', 'graphiql'); - $schemaName = $this->findSchemaNameInRequest($request, "/$routePrefix"); - - $graphqlPath = '/' . $config->get('graphql.route.prefix', 'graphql'); - - if ($schemaName) { - $graphqlPath .= '/' . $schemaName; - } - - $graphqlPath = '/' . trim($graphqlPath, '/'); - - $view = $config->get('graphql.graphiql.view', 'graphql::graphiql'); - - return $viewFactory->make($view, [ - 'graphqlPath' => $graphqlPath, - 'schema' => $schemaName, - ]); - } - /** * In case batching is not supported, send an error back for each batch * (with a hardcoded limit of 100). diff --git a/src/GraphQLServiceProvider.php b/src/GraphQLServiceProvider.php index 34f54d1a..60c6b681 100644 --- a/src/GraphQLServiceProvider.php +++ b/src/GraphQLServiceProvider.php @@ -54,9 +54,6 @@ protected function bootPublishes(): void $this->publishes([ $configPath . '/config.php' => $this->app->configPath() . '/graphql.php', ], 'config'); - - $viewsPath = __DIR__ . '/../resources/views'; - $this->loadViewsFrom($viewsPath, 'graphql'); } /** diff --git a/src/routes.php b/src/routes.php index 2e118f51..0a3e0d19 100644 --- a/src/routes.php +++ b/src/routes.php @@ -62,38 +62,3 @@ function (Router $router) use ($config, $routeConfig): void { } ); } - -if ($config->get('graphql.graphiql.display', true)) { - /** @var Router $router */ - $router = app('router'); - $graphiqlConfig = $config->get('graphql.graphiql'); - - $router->group( - [ - 'prefix' => $graphiqlConfig['prefix'] ?? 'graphiql', - 'middleware' => $graphiqlConfig['middleware'] ?? [], - ], - function (Router $router) use ($config, $graphiqlConfig): void { - // Support array syntax: `[Some::class, 'method']` - if (\is_array($graphiqlConfig['controller']) && isset($graphiqlConfig['controller'][0], $graphiqlConfig['controller'][1])) { - $graphiqlConfig['controller'] = $graphiqlConfig['controller'][0] . '@' . $graphiqlConfig['controller'][1]; - } - - $actions = [ - 'uses' => $graphiqlConfig['controller'] ?? GraphQLController::class . '@graphiql', - ]; - - // A graphiql route for each schema… - /** @var string $schemaName */ - foreach (array_keys($config->get('graphql.schemas', [])) as $schemaName) { - $router->get( - $schemaName, - $actions + ['as' => "graphql.graphiql.$schemaName"] - ); - } - - // … and one for the default schema against the group itself - $router->get('/', $actions + ['as' => 'graphql.graphiql']); - } - ); -} diff --git a/tests/Unit/Config/ControllersFormatTest.php b/tests/Unit/Config/ControllersFormatTest.php index 43bed2d4..b548aff7 100644 --- a/tests/Unit/Config/ControllersFormatTest.php +++ b/tests/Unit/Config/ControllersFormatTest.php @@ -28,10 +28,6 @@ protected function getEnvironmentSetUp($app): void 'types' => [ 'Example' => ExampleType::class, ], - - 'graphiql' => [ - 'controller' => [GraphQLController::class, 'graphiql'], - ], ]); } @@ -43,11 +39,4 @@ public function testControllerHasValidMethod(): void self::assertSame(200, $response->getStatusCode()); } - - public function testGraphiQLHasValidMethod(): void - { - $response = $this->call('GET', '/graphiql'); - - self::assertSame(200, $response->getStatusCode()); - } } diff --git a/tests/Unit/Console/PublishCommandTest.php b/tests/Unit/Console/PublishCommandTest.php index eaab503c..81508846 100644 --- a/tests/Unit/Console/PublishCommandTest.php +++ b/tests/Unit/Console/PublishCommandTest.php @@ -20,7 +20,7 @@ public function testCommand(): void ]) ->getMock(); $filesystemMock - ->expects(self::exactly(2)) + ->expects(self::exactly(1)) ->method('copy') ->withConsecutive( [ @@ -39,26 +39,6 @@ public function testCommand(): void return true; }), ], - [ - self::callback(function (string $from): bool { - $this->assertMatchesRegularExpression( - '|/resources/views/graphiql.php|', - $from, - '2nd call to copy, $from' - ); - - return true; - }), - self::callback(function (string $to): bool { - $this->assertMatchesRegularExpression( - '|laravel[/\\\\]resources/views/vendor/graphql/graphiql.php|', - $to, - '2nd call to copy, $to' - ); - - return true; - }), - ] ); $this->instance(Filesystem::class, $filesystemMock); @@ -68,9 +48,5 @@ public function testCommand(): void self::assertSame(0, $tester->getStatusCode()); self::assertMatchesRegularExpression('|Copied File.*[/\\\\]config[/\\\\]config.php.* To|', $tester->getDisplay()); - self::assertMatchesRegularExpression( - '|Copied File.*[/\\\\]resources[/\\\\]views[/\\\\]graphiql.php.* To|', - $tester->getDisplay() - ); } } diff --git a/tests/Unit/EmptyRoutePrefixTest.php b/tests/Unit/EmptyRoutePrefixTest.php index 6f4fc457..a38ef5d9 100644 --- a/tests/Unit/EmptyRoutePrefixTest.php +++ b/tests/Unit/EmptyRoutePrefixTest.php @@ -31,18 +31,4 @@ public function testGetCustomSchema(): void self::assertEquals(200, $response->getStatusCode()); } - - public function testGetGraphiQL(): void - { - $response = $this->call('GET', '/graphiql'); - - $response->assertSee('return fetch(\'/\', {', false); - } - - public function testGetGraphiQLCustomSchema(): void - { - $response = $this->call('GET', '/graphiql/custom'); - - $response->assertSee('return fetch(\'/custom\', {', false); - } } diff --git a/tests/Unit/EndpointTest.php b/tests/Unit/EndpointTest.php index 007a6605..cee21d88 100644 --- a/tests/Unit/EndpointTest.php +++ b/tests/Unit/EndpointTest.php @@ -215,26 +215,4 @@ public function testBatchedQueriesButBatchingDisabled(): void ]; self::assertEquals($expected, $actual); } - - public function testGetGraphiQL(): void - { - $response = $this->call('GET', '/graphiql'); - - // Are we seeing the right template? - $response->assertSee('This GraphiQL example illustrates how to use some of GraphiQL\'s props', false); - // The argument to fetch is extracted from the configuration - $response->assertSee('return fetch(\'/graphql\', {', false); - $response->assertSee("'x-csrf-token': xcsrfToken || ''", false); - } - - public function testGetGraphiQLCustomSchema(): void - { - $response = $this->call('GET', '/graphiql/custom'); - - // Are we seeing the right template? - $response->assertSee('This GraphiQL example illustrates how to use some of GraphiQL\'s props', false); - // The argument to fetch is extracted from the configuration - $response->assertSee('return fetch(\'/graphql/custom\', {', false); - $response->assertSee("'x-csrf-token': xcsrfToken || ''", false); - } } diff --git a/tests/Unit/NoRoutesRegisteredTest.php b/tests/Unit/NoRoutesRegisteredTest.php index c6722b3e..ca8ad6d6 100644 --- a/tests/Unit/NoRoutesRegisteredTest.php +++ b/tests/Unit/NoRoutesRegisteredTest.php @@ -16,10 +16,6 @@ protected function getEnvironmentSetUp($app): void { $app['config']->set('graphql', [ 'route' => [], - 'graphiql' => [ - 'display' => false, - ], - 'schemas' => [ 'default' => [ 'middleware' => [ExampleMiddleware::class], diff --git a/tests/Unit/RoutesTest.php b/tests/Unit/RoutesTest.php index 62615680..c64c5745 100644 --- a/tests/Unit/RoutesTest.php +++ b/tests/Unit/RoutesTest.php @@ -19,10 +19,6 @@ protected function getEnvironmentSetUp($app): void 'prefix' => 'graphql_test', ], - 'graphiql' => [ - 'display' => false, - ], - 'schemas' => [ 'default' => [ 'middleware' => [ExampleMiddleware::class], diff --git a/tests/integration-laravel.sh b/tests/integration-laravel.sh index 49f78c20..aca8d933 100755 --- a/tests/integration-laravel.sh +++ b/tests/integration-laravel.sh @@ -53,15 +53,3 @@ else cat storage/logs/* exit 1 fi - -echo "Test accessing GraphiQL" -curl 'http://127.0.0.1:8001/graphiql' -sSfLv | grep '
Loading...
' - -if [[ $? = 0 ]]; then - echo "Can access GraphiQL 👍" -else - echo "Cannot access GraphiQL 🚨" - curl 'http://127.0.0.1:8001/graphiql' -sSfLv - cat storage/logs/* - exit 1 -fi