Skip to content

Commit 53f2618

Browse files
committed
MC-21524: Schema introspection return incomplete results
- Added test for introspection test
1 parent 910415f commit 53f2618

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

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

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,124 @@ public function testIntrospectionQuery()
5656
$this->assertArrayHasKey('__schema', $this->graphQlQuery($query));
5757
}
5858

59+
/**
60+
* Tests that Introspection is allowed by default
61+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
62+
*/
63+
public function testIntrospectionQueryWithOnlySchema()
64+
{
65+
$query
66+
= <<<QUERY
67+
{
68+
__schema {
69+
queryType { name }
70+
types{
71+
...FullType
72+
}
73+
}
74+
}
75+
fragment FullType on __Type{
76+
name
77+
kind
78+
fields(includeDeprecated:true){
79+
name
80+
args{
81+
...InputValue
82+
}
83+
}
84+
}
85+
86+
fragment TypeRef on __Type {
87+
kind
88+
name
89+
ofType{
90+
kind
91+
name
92+
}
93+
}
94+
fragment InputValue on __InputValue {
95+
name
96+
description
97+
type { ...TypeRef }
98+
defaultValue
99+
}
100+
QUERY;
101+
$this->assertArrayHasKey('__schema', $this->graphQlQuery($query));
102+
$response = $this->graphQlQuery($query);
103+
104+
$query
105+
= <<<QUERY
106+
query IntrospectionQuery {
107+
__schema {
108+
queryType { name }
109+
types{
110+
...FullType
111+
}
112+
}
113+
}
114+
fragment FullType on __Type{
115+
name
116+
kind
117+
fields(includeDeprecated:true){
118+
name
119+
args{
120+
...InputValue
121+
}
122+
}
123+
}
124+
125+
fragment TypeRef on __Type {
126+
kind
127+
name
128+
ofType{
129+
kind
130+
name
131+
}
132+
}
133+
fragment InputValue on __InputValue {
134+
name
135+
description
136+
type { ...TypeRef }
137+
defaultValue
138+
}
139+
QUERY;
140+
$this->assertArrayHasKey('__schema', $this->graphQlQuery($query));
141+
$responseFields = $this->graphQlQuery($query);
142+
$this->assertResponseFields($response, $responseFields);
143+
$this->assertEquals($responseFields, $response);
144+
}
145+
146+
/**
147+
* Tests that Introspection is allowed by default
148+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
149+
*/
150+
public function testIntrospectionQueryWithOnlyType()
151+
{
152+
$query
153+
= <<<QUERY
154+
{
155+
__type(name:"Query")
156+
{
157+
name
158+
kind
159+
fields(includeDeprecated:true){
160+
name
161+
type{
162+
kind
163+
name
164+
}
165+
description
166+
isDeprecated
167+
deprecationReason
168+
}
169+
}
170+
}
171+
QUERY;
172+
$this->assertArrayHasKey('__type', $this->graphQlQuery($query));
173+
$response = $this->graphQlQuery($query);
174+
$this->assertNotEmpty($response['__type']['fields']);
175+
}
176+
59177
/**
60178
* Tests that Introspection Query with deprecated annotations on enum values, fields are read.
61179
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function setQuery($query, array $variables = null)
6161
* Get list of fields used in GraphQL query.
6262
*
6363
* This method is stateful and relies on the query being set with setQuery.
64-
*-
64+
*
6565
* @return string[]
6666
*/
6767
public function getFieldsUsedInQuery()

0 commit comments

Comments
 (0)