Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

❗BREAKING CHANGE❗️ Remove GraphiQL integration #986

Merged
merged 1 commit into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------
Expand Down
34 changes: 2 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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/<schema name>`.

### Middleware Overview

The following middleware concepts are supported:
Expand Down Expand Up @@ -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`\
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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)
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,8 @@
"config": {
"preferred-install": "dist",
"sort-packages": true
},
"suggest": {
"mll-lab/laravel-graphiql": "Easily integrate GraphiQL into your Laravel projects. "
}
}
11 changes: 0 additions & 11 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions resources/views/README.md

This file was deleted.

154 changes: 0 additions & 154 deletions resources/views/graphiql.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Console/PublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
}

Expand Down
23 changes: 0 additions & 23 deletions src/GraphQLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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).
Expand Down
3 changes: 0 additions & 3 deletions src/GraphQLServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
35 changes: 0 additions & 35 deletions src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
);
}
11 changes: 0 additions & 11 deletions tests/Unit/Config/ControllersFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ protected function getEnvironmentSetUp($app): void
'types' => [
'Example' => ExampleType::class,
],

'graphiql' => [
'controller' => [GraphQLController::class, 'graphiql'],
],
]);
}

Expand All @@ -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());
}
}
Loading