Skip to content

Commit

Permalink
enableGql config setting
Browse files Browse the repository at this point in the history
Resolves #4836
  • Loading branch information
brandonkelly committed Aug 29, 2019
1 parent e7827b0 commit 859e990
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

### Added
- Added the `enableGql` config setting. ([#4836](https://github.com/craftcms/cms/issues/4836))
- Added the `children` field to the `EntryInterface` and `CategoryInterface` GraphQL types. ([#4843](https://github.com/craftcms/cms/issues/4843))
- Added the `markdown` GraphQL directive. ([#4832](https://github.com/craftcms/cms/issues/4832))

Expand Down
22 changes: 22 additions & 0 deletions docs/config/config-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,28 @@ Whether to enable CSRF protection via hidden form inputs for all forms submitted



### `enableGql`

Allowed types

: [boolean](http://php.net/language.types.boolean)

Default value

: `true`

Defined by

: [GeneralConfig::$enableGql](api:craft\config\GeneralConfig::$enableGql)



Whether the GraphQL API should be enabled.

Note that the GraphQL API is only available for Craft Pro.



### `enableTemplateCaching`

Allowed types
Expand Down
6 changes: 6 additions & 0 deletions src/config/GeneralConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ class GeneralConfig extends BaseObject
* @see enableCsrfProtection
*/
public $enableCsrfCookie = true;
/**
* @var bool Whether the GraphQL API should be enabled.
*
* Note that the GraphQL API is only available for Craft Pro.
*/
public $enableGql = true;
/**
* @var mixed The amount of time a user’s elevated session will last, which is required for some sensitive actions (e.g. user group/permission assignment).
*
Expand Down
9 changes: 7 additions & 2 deletions src/controllers/GraphqlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
use yii\web\NotFoundHttpException;
use yii\web\Response;

Craft::$app->requireEdition(Craft::Pro);

/**
* The GqlController class is a controller that handles various GraphQL related tasks.
*
Expand All @@ -43,9 +41,16 @@ class GraphqlController extends Controller

/**
* @inheritdoc
* @throws NotFoundHttpException
*/
public function beforeAction($action)
{
if (!Craft::$app->getConfig()->getGeneral()->enableGql) {
throw new NotFoundHttpException(Craft::t('yii', 'Page not found.'));
}

Craft::$app->requireEdition(Craft::Pro);

if ($action->id === 'api') {
$this->enableCsrfValidation = false;
}
Expand Down
5 changes: 3 additions & 2 deletions src/web/twig/variables/Cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function nav(): array
{
$craftPro = Craft::$app->getEdition() === Craft::Pro;
$isAdmin = Craft::$app->getUser()->getIsAdmin();
$generalConfig = Craft::$app->getConfig()->getGeneral();

$navItems = [
[
Expand Down Expand Up @@ -194,7 +195,7 @@ public function nav(): array
}

if ($isAdmin) {
if ($craftPro) {
if ($craftPro && $generalConfig->enableGql) {
$navItems[] = [
'label' => Craft::t('app', 'GraphQL'),
'url' => 'graphql',
Expand All @@ -212,7 +213,7 @@ public function nav(): array
];
}

if (Craft::$app->getConfig()->getGeneral()->allowAdminChanges) {
if ($generalConfig->allowAdminChanges) {
$navItems[] = [
'url' => 'settings',
'label' => Craft::t('app', 'Settings'),
Expand Down

0 comments on commit 859e990

Please sign in to comment.