Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GraphQlIntrospectionTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
8 namespace Magento\GraphQl;
9 
13 
14 class GraphQlIntrospectionTest extends \PHPUnit\Framework\TestCase
15 {
17  private $schemaFactory;
18 
20  private $objectManager;
21 
22  protected function setUp()
23  {
25  $this->schemaFactory = $this->objectManager->get(\Magento\Framework\GraphQl\SchemaFactory::class);
26  }
27 
28  public function testIntrospectionQuery()
29  {
30  $emptySchema = $this->schemaFactory->create(
31  [
32  'query' => new ObjectType(
33  [
34  'name' => 'Query',
35  'description' =>'Description at type level',
36  'fields' => ['a' => \GraphQL\Type\Definition\Type::string()]
37  ]
38  )
39  ]
40  );
41  $request =
42  <<<QUERY
43 query IntrospectionQuery {
44 __schema {
45 queryType { name }
46 types{
47 ...FullType
48 }
49 }
50 }
51 fragment FullType on __Type{
52 name
53 description
54 kind
55 fields(includeDeprecated:true){
56 name
57 args{
58 ...InputValue
59 }
60  }
61 }
62 
63 fragment TypeRef on __Type {
64 kind
65 name
66 ofType{
67 kind
68 name
69 }
70 }
71 fragment InputValue on __InputValue {
72 name
73 description
74 type { ...TypeRef }
75 defaultValue
76 }
77 QUERY;
78  $response = \GraphQL\GraphQL::executeQuery($emptySchema, $request);
79  $output = $response->toArray()['data']['__schema'];
80  $this->assertEquals('Query', $output['queryType']['name']);
81  $this->assertEquals($output['types'][0]['kind'], 'OBJECT');
82  $expectedFragment =
83  [
84  'name' => 'Query',
85  'description' => 'Description at type level',
86  'kind' => 'OBJECT',
87  'fields' => [
88  [
89  'name' => 'a',
90  'args' => []
91  ]
92  ]
93  ];
94  $this->assertContains($expectedFragment, $output['types']);
95  }
96 
102  {
103  $testInputObject = new InputObjectType(
104  [
105  'name' => 'ProductFilterInput',
106  'fields' => [
107  'attributeA' => [
108  'type' => \GraphQL\Type\Definition\Type::nonNull(
109  \GraphQL\Type\Definition\Type::string()
110  ),
111  'description' => 'testDescriptionForA'
112  ],
113  'attributeB' => [
114  'type' => \GraphQL\Type\Definition\Type::listOf(
115  \GraphQL\Type\Definition\Type::string()
116  )
117  ],
118  'attributeC' => ['type' => \GraphQL\Type\Definition\Type::string(), 'defaultValue' => null],
119  'attributeD' => [
120  'type' => \GraphQL\Type\Definition\Type::string(),
121  'defaultValue' => 'test',
122  'description' => 'testDescriptionForD'
123  ],
124  ]
125  ]
126  );
127  $TestType = new ObjectType([
128  'name' => 'Query',
129  'fields' => [
130  'field' => [
131  'type' => \GraphQL\Type\Definition\Type::string(),
132  'args' => ['complex' => ['type' => $testInputObject]],
133  'resolve' => function ($args) {
134  return json_encode($args['complex']);
135  }
136  ]
137  ]
138  ]);
139  $testSchema = $this->schemaFactory->create(
140  ['query' => $TestType]
141  );
142 
143  $request =
144  <<<QUERY
145 {
146  __schema {
147  types {
148  kind
149  name
150  inputFields {
151  name
152  description
153  type { ...TypeRef }
154  defaultValue
155  }
156  }
157  }
158  }
159  fragment TypeRef on __Type {
160  kind
161  name
162  ofType {
163  kind
164  name
165  ofType {
166  kind
167  name
168  ofType {
169  kind
170  name
171  }
172  }
173  }
174 }
175 QUERY;
176  $response = \GraphQL\GraphQL::executeQuery($testSchema, $request);
177  $expectedResult =
178  [
179  'kind'=> 'INPUT_OBJECT',
180  'name'=> 'ProductFilterInput',
181  'inputFields'=> [
182  [
183  'name'=> 'attributeA',
184  'description'=> 'testDescriptionForA',
185  'type'=> [
186  'kind'=> 'NON_NULL',
187  'name'=> null,
188  'ofType'=> [
189  'kind'=> 'SCALAR',
190  'name'=> 'String',
191  'ofType'=> null
192  ]
193  ],
194  'defaultValue'=> null
195  ],
196  [
197  'name'=> 'attributeB',
198  'description'=> null,
199  'type'=> [
200  'kind'=> 'LIST',
201  'name'=> null,
202  'ofType'=> [
203  'kind'=> 'SCALAR',
204  'name'=> 'String',
205  'ofType'=> null
206  ]
207  ],
208  'defaultValue'=> null
209  ],
210  [
211  'name'=> 'attributeC',
212  'description'=> null,
213  'type'=> [
214  'kind'=> 'SCALAR',
215  'name'=> 'String',
216  'ofType'=> null
217  ],
218  'defaultValue'=> 'null'
219  ],
220  [
221  'name'=> 'attributeD',
222  'description'=> 'testDescriptionForD',
223  'type'=> [
224  'kind'=> 'SCALAR',
225  'name'=> 'String',
226  'ofType'=> null
227  ],
228  'defaultValue'=> '"test"'
229  ]
230  ]
231  ];
232  $output = $response->toArray()['data']['__schema']['types'];
233  $this->assertContains($expectedResult, $output);
234  }
235 
240  {
241  $testSchema = $this->schemaFactory->create(
242  [
243  'query' => new ObjectType(
244  [
245  'name' => 'Query',
246  'fields' => [
247  'deprecated' => [
248  'type' => \GraphQL\Type\Definition\Type::string(),
249  'deprecationReason' =>'Deprecated in an older version'
250  ],
251  'nonDeprecated' => [
252  'type' => \GraphQL\Type\Definition\Type::string()
253  ]
254  ]
255  ]
256  )
257  ]
258  );
259  $request =
260  <<<QUERY
261  {
262  __type(name:"Query")
263  {
264  name
265  kind
266  fields(includeDeprecated:true){
267  name
268  type{
269  kind
270  name
271  }
272  description
273  isDeprecated
274  deprecationReason
275 
276  }
277  }
278 }
279 
280 QUERY;
281  $response = \GraphQL\GraphQL::executeQuery($testSchema, $request);
282  $output = $response->toArray()['data']['__type'];
283  $expectedResult =
284  [
285  "name" =>"Query",
286  "kind" =>"OBJECT",
287  "fields" => [
288  [
289  'name'=> 'deprecated',
290  'type'=> [
291  'kind'=> 'SCALAR',
292  'name'=> 'String'
293  ],
294  'description'=> null,
295  'isDeprecated'=> true,
296  'deprecationReason'=> 'Deprecated in an older version'
297  ],
298  [
299  'name'=> 'nonDeprecated',
300  'type'=> [
301  'kind'=> 'SCALAR',
302  'name'=> 'String'
303  ],
304  'description'=> null,
305  'isDeprecated'=> false,
306  'deprecationReason'=> null
307  ]
308  ]
309  ];
310  $this->assertEquals($expectedResult, $output);
311  }
312 }
$response
Definition: 404.php:11
taxRateField this edit on("click.mselect-delete", ".mselect-delete", function() { if(!confirm('<?=/*@escapeNotVerified */__( 'Do you really want to delete this tax rate?') ?>')) { return;} var that=$(this), select=that.closest('.mselect-list').prev(), rateValue=that.parent().find( 'input[type="checkbox"]').val();$( 'body').trigger( 'processStart');var ajaxOptions={ type:'POST', data:{ tax_calculation_rate_id:rateValue, form_key:$( 'input[name="form_key"]').val() }, dataType:'json', url:'<?=/*@escapeNotVerified */$block->getTaxRateDeleteUrl() ?>', success:function(result, status) { $( 'body').trigger( 'processStop');if(result.success) { that.parent().remove();select.find( 'option').each(function() { if(this.value===rateValue) { $(this).remove();} });select.trigger( 'change.hiddenSelect');} else { if(result.error_message) alert({ content:result.error_message });else alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} }, error:function() { $( 'body').trigger( 'processStop');alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} };$.ajax(ajaxOptions);}) .on( 'click.mselectAdd'
Definition: edit.phtml:164