Skip to content

Commit 97fd70f

Browse files
authored
Merge pull request magento#3666 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
2 parents 4f23251 + 2f892c9 commit 97fd70f

File tree

4 files changed

+87
-10
lines changed

4 files changed

+87
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
10+
<arguments>
11+
<argument name="extendedConfigData" xsi:type="array">
12+
<item name="head_shortcut_icon" xsi:type="string">design/head/shortcut_icon</item>
13+
<item name="default_title" xsi:type="string">design/head/default_title</item>
14+
<item name="title_prefix" xsi:type="string">design/head/title_prefix</item>
15+
<item name="title_suffix" xsi:type="string">design/head/title_suffix</item>
16+
<item name="default_description" xsi:type="string">design/head/default_description</item>
17+
<item name="default_keywords" xsi:type="string">design/head/default_keywords</item>
18+
<item name="head_includes" xsi:type="string">design/head/includes</item>
19+
<item name="demonotice" xsi:type="string">design/head/demonotice</item>
20+
<item name="header_logo_src" xsi:type="string">design/header/logo_src</item>
21+
<item name="logo_width" xsi:type="string">design/header/logo_width</item>
22+
<item name="logo_height" xsi:type="string">design/header/logo_height</item>
23+
<item name="logo_alt" xsi:type="string">design/header/logo_alt</item>
24+
<item name="welcome" xsi:type="string">design/header/welcome</item>
25+
<item name="absolute_footer" xsi:type="string">design/footer/absolute_footer</item>
26+
<item name="copyright" xsi:type="string">design/footer/copyright</item>
27+
</argument>
28+
</arguments>
29+
</type>
30+
</config>

dev/tests/api-functional/testsuite/Magento/GraphQl/IntrospectionQueryTest.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
class IntrospectionQueryTest extends GraphQlAbstract
1313
{
1414
/**
15-
* Tests that Introspection is disabled when not in developer mode
15+
* Tests that Introspection is allowed by default
1616
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
1717
*/
18-
public function testIntrospectionQueryWithFieldArgs()
18+
public function testIntrospectionQuery()
1919
{
2020
$query
2121
= <<<QUERY
@@ -54,11 +54,6 @@ public function testIntrospectionQueryWithFieldArgs()
5454
}
5555
QUERY;
5656

57-
$this->expectException(\Exception::class);
58-
$this->expectExceptionMessage(
59-
'GraphQL response contains errors: GraphQL introspection is not allowed, but ' .
60-
'the query contained __schema or __type'
61-
);
62-
$this->graphQlQuery($query);
57+
$this->assertArrayHasKey('__schema', $this->graphQlQuery($query));
6358
}
6459
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\GraphQl\Query;
9+
10+
use Magento\Framework\App\DeploymentConfig;
11+
12+
/**
13+
* Class for fetching the availability of introspection queries
14+
*/
15+
class IntrospectionConfiguration
16+
{
17+
private const CONFIG_PATH_DISABLE_INTROSPECTION = 'graphql/disable_introspection';
18+
19+
/**
20+
* @var DeploymentConfig
21+
*/
22+
private $deploymentConfig;
23+
24+
/**
25+
* @param DeploymentConfig $deploymentConfig
26+
*/
27+
public function __construct(
28+
DeploymentConfig $deploymentConfig
29+
) {
30+
$this->deploymentConfig = $deploymentConfig;
31+
}
32+
33+
/**
34+
* Check the the environment config to determine if introspection should be disabled.
35+
*
36+
* @return bool
37+
*/
38+
public function isIntrospectionDisabled(): bool
39+
{
40+
return (bool)$this->deploymentConfig->get(self::CONFIG_PATH_DISABLE_INTROSPECTION);
41+
}
42+
}

lib/internal/Magento/Framework/GraphQl/Query/QueryComplexityLimiter.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,24 @@ class QueryComplexityLimiter
3333
*/
3434
private $queryComplexity;
3535

36+
/**
37+
* @var IntrospectionConfiguration
38+
*/
39+
private $introspectionConfig;
40+
3641
/**
3742
* @param int $queryDepth
3843
* @param int $queryComplexity
44+
* @param IntrospectionConfiguration $introspectionConfig
3945
*/
4046
public function __construct(
4147
int $queryDepth,
42-
int $queryComplexity
48+
int $queryComplexity,
49+
IntrospectionConfiguration $introspectionConfig
4350
) {
4451
$this->queryDepth = $queryDepth;
4552
$this->queryComplexity = $queryComplexity;
53+
$this->introspectionConfig = $introspectionConfig;
4654
}
4755

4856
/**
@@ -53,7 +61,9 @@ public function __construct(
5361
public function execute(): void
5462
{
5563
DocumentValidator::addRule(new QueryComplexity($this->queryComplexity));
56-
DocumentValidator::addRule(new DisableIntrospection());
64+
DocumentValidator::addRule(
65+
new DisableIntrospection((int) $this->introspectionConfig->isIntrospectionDisabled())
66+
);
5767
DocumentValidator::addRule(new QueryDepth($this->queryDepth));
5868
}
5969
}

0 commit comments

Comments
 (0)