File tree 3 files changed +55
-10
lines changed
dev/tests/api-functional/testsuite/Magento/GraphQl
lib/internal/Magento/Framework/GraphQl/Query
3 files changed +55
-10
lines changed Original file line number Diff line number Diff line change 12
12
class IntrospectionQueryTest extends GraphQlAbstract
13
13
{
14
14
/**
15
- * Tests that Introspection is disabled when not in developer mode
15
+ * Tests that Introspection is allowed by default
16
16
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
17
17
*/
18
- public function testIntrospectionQueryWithFieldArgs ()
18
+ public function testIntrospectionQuery ()
19
19
{
20
20
$ query
21
21
= <<<QUERY
@@ -54,11 +54,6 @@ public function testIntrospectionQueryWithFieldArgs()
54
54
}
55
55
QUERY ;
56
56
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 ));
63
58
}
64
59
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -33,16 +33,24 @@ class QueryComplexityLimiter
33
33
*/
34
34
private $ queryComplexity ;
35
35
36
+ /**
37
+ * @var IntrospectionConfiguration
38
+ */
39
+ private $ introspectionConfig ;
40
+
36
41
/**
37
42
* @param int $queryDepth
38
43
* @param int $queryComplexity
44
+ * @param IntrospectionConfiguration $introspectionConfig
39
45
*/
40
46
public function __construct (
41
47
int $ queryDepth ,
42
- int $ queryComplexity
48
+ int $ queryComplexity ,
49
+ IntrospectionConfiguration $ introspectionConfig
43
50
) {
44
51
$ this ->queryDepth = $ queryDepth ;
45
52
$ this ->queryComplexity = $ queryComplexity ;
53
+ $ this ->introspectionConfig = $ introspectionConfig ;
46
54
}
47
55
48
56
/**
@@ -53,7 +61,7 @@ public function __construct(
53
61
public function execute (): void
54
62
{
55
63
DocumentValidator::addRule (new QueryComplexity ($ this ->queryComplexity ));
56
- DocumentValidator::addRule (new DisableIntrospection ());
64
+ DocumentValidator::addRule (new DisableIntrospection (( int ) $ this -> introspectionConfig -> isIntrospectionDisabled () ));
57
65
DocumentValidator::addRule (new QueryDepth ($ this ->queryDepth ));
58
66
}
59
67
}
You can’t perform that action at this time.
0 commit comments