Passed
Pull Request — master (#335)
by Šimon
04:38
created

testFailsAsExpectedOnTheTypeRootFieldWithoutAnArg()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 27
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace GraphQL\Tests\Type;
3
4
use GraphQL\Error\FormattedError;
5
use GraphQL\Language\SourceLocation;
6
use GraphQL\Type\Schema;
7
use GraphQL\GraphQL;
8
use GraphQL\Type\Definition\EnumType;
9
use GraphQL\Type\Definition\InputObjectType;
10
use GraphQL\Type\Definition\ObjectType;
11
use GraphQL\Type\Definition\Type;
12
use GraphQL\Type\Introspection;
13
use GraphQL\Validator\Rules\ProvidedNonNullArguments;
14
use PHPUnit\Framework\TestCase;
15
16
class IntrospectionTest extends TestCase
17
{
18
    // Describe: Introspection
19
20
    /**
21
     * @see it('executes an introspection query')
22
     */
23
    function testExecutesAnIntrospectionQuery()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
24
    {
25
        $emptySchema = new Schema([
26
            'query' => new ObjectType([
27
                'name' => 'QueryRoot',
28
                'fields' => ['a' => Type::string()]
29
            ])
30
        ]);
31
32
        $request = Introspection::getIntrospectionQuery(['descriptions' => false]);
33
        $expected = array (
34
            'data' =>
35
                array (
36
                    '__schema' =>
37
                        array (
38
                            'mutationType' => NULL,
39
                            'subscriptionType' => NULL,
40
                            'queryType' =>
41
                                array (
42
                                    'name' => 'QueryRoot',
43
                                ),
44
                            'types' =>
45
                                array (
46
                                    array (
47
                                        'kind' => 'OBJECT',
48
                                        'name' => 'QueryRoot',
49
                                        'inputFields' => NULL,
50
                                        'interfaces' =>
51
                                            array (
52
                                            ),
53
                                        'enumValues' => NULL,
54
                                        'possibleTypes' => NULL,
55
                                        'fields' => array (
56
                                            array (
57
                                                'name' => 'a',
58
                                                'args' => array(),
59
                                                'type' => array(
60
                                                    'kind' => 'SCALAR',
61
                                                    'name' => 'String',
62
                                                    'ofType' => null
63
                                                ),
64
                                                'isDeprecated' => false,
65
                                                'deprecationReason' => null,
66
                                            )
67
                                        )
68
                                    ),
69
                                    array (
70
                                        'kind' => 'SCALAR',
71
                                        'name' => 'String',
72
                                        'fields' => NULL,
73
                                        'inputFields' => NULL,
74
                                        'interfaces' => NULL,
75
                                        'enumValues' => NULL,
76
                                        'possibleTypes' => NULL,
77
                                    ),
78
                                    array (
79
                                        'kind' => 'SCALAR',
80
                                        'name' => 'ID',
81
                                        'fields' => NULL,
82
                                        'inputFields' => NULL,
83
                                        'interfaces' => NULL,
84
                                        'enumValues' => NULL,
85
                                        'possibleTypes' => NULL,
86
                                    ),
87
                                    array (
88
                                        'kind' => 'SCALAR',
89
                                        'name' => 'Float',
90
                                        'fields' => NULL,
91
                                        'inputFields' => NULL,
92
                                        'interfaces' => NULL,
93
                                        'enumValues' => NULL,
94
                                        'possibleTypes' => NULL,
95
                                    ),
96
                                    array (
97
                                        'kind' => 'SCALAR',
98
                                        'name' => 'Int',
99
                                        'fields' => NULL,
100
                                        'inputFields' => NULL,
101
                                        'interfaces' => NULL,
102
                                        'enumValues' => NULL,
103
                                        'possibleTypes' => NULL,
104
                                    ),
105
                                    array (
106
                                        'kind' => 'SCALAR',
107
                                        'name' => 'Boolean',
108
                                        'fields' => NULL,
109
                                        'inputFields' => NULL,
110
                                        'interfaces' => NULL,
111
                                        'enumValues' => NULL,
112
                                        'possibleTypes' => NULL,
113
                                    ),
114
                                    array (
115
                                        'kind' => 'OBJECT',
116
                                        'name' => '__Schema',
117
                                        'fields' =>
118
                                            array (
119
                                                0 =>
120
                                                    array (
121
                                                        'name' => 'types',
122
                                                        'args' =>
123
                                                            array (
124
                                                            ),
125
                                                        'type' =>
126
                                                            array (
127
                                                                'kind' => 'NON_NULL',
128
                                                                'name' => NULL,
129
                                                                'ofType' =>
130
                                                                    array (
131
                                                                        'kind' => 'LIST',
132
                                                                        'name' => NULL,
133
                                                                        'ofType' =>
134
                                                                            array (
135
                                                                                'kind' => 'NON_NULL',
136
                                                                                'name' => NULL,
137
                                                                                'ofType' =>
138
                                                                                    array (
139
                                                                                        'kind' => 'OBJECT',
140
                                                                                        'name' => '__Type'
141
                                                                                    ),
142
                                                                            ),
143
                                                                    ),
144
                                                            ),
145
                                                        'isDeprecated' => false,
146
                                                        'deprecationReason' => NULL,
147
                                                    ),
148
                                                1 =>
149
                                                    array (
150
                                                        'name' => 'queryType',
151
                                                        'args' =>
152
                                                            array (
153
                                                            ),
154
                                                        'type' =>
155
                                                            array (
156
                                                                'kind' => 'NON_NULL',
157
                                                                'name' => NULL,
158
                                                                'ofType' =>
159
                                                                    array (
160
                                                                        'kind' => 'OBJECT',
161
                                                                        'name' => '__Type',
162
                                                                    ),
163
                                                            ),
164
                                                        'isDeprecated' => false,
165
                                                        'deprecationReason' => NULL,
166
                                                    ),
167
                                                array (
168
                                                    'name' => 'mutationType',
169
                                                    'args' =>
170
                                                        array (
171
                                                        ),
172
                                                    'type' =>
173
                                                        array (
174
                                                            'kind' => 'OBJECT',
175
                                                            'name' => '__Type',
176
                                                        ),
177
                                                    'isDeprecated' => false,
178
                                                    'deprecationReason' => NULL,
179
                                                ),
180
                                                array (
181
                                                    'name' => 'subscriptionType',
182
                                                    'args' =>
183
                                                        array (
184
                                                        ),
185
                                                    'type' =>
186
                                                        array (
187
                                                            'kind' => 'OBJECT',
188
                                                            'name' => '__Type',
189
                                                        ),
190
                                                    'isDeprecated' => false,
191
                                                    'deprecationReason' => NULL,
192
                                                ),
193
                                                array (
194
                                                    'name' => 'directives',
195
                                                    'args' =>
196
                                                        array (
197
                                                        ),
198
                                                    'type' =>
199
                                                        array (
200
                                                            'kind' => 'NON_NULL',
201
                                                            'name' => NULL,
202
                                                            'ofType' =>
203
                                                                array (
204
                                                                    'kind' => 'LIST',
205
                                                                    'name' => NULL,
206
                                                                    'ofType' =>
207
                                                                        array (
208
                                                                            'kind' => 'NON_NULL',
209
                                                                            'name' => NULL,
210
                                                                            'ofType' =>
211
                                                                                array (
212
                                                                                    'kind' => 'OBJECT',
213
                                                                                    'name' => '__Directive',
214
                                                                                ),
215
                                                                        ),
216
                                                                ),
217
                                                        ),
218
                                                    'isDeprecated' => false,
219
                                                    'deprecationReason' => NULL,
220
                                                ),
221
                                            ),
222
                                        'inputFields' => NULL,
223
                                        'interfaces' =>
224
                                            array (
225
                                            ),
226
                                        'enumValues' => NULL,
227
                                        'possibleTypes' => NULL,
228
                                    ),
229
                                    array (
230
                                        'kind' => 'OBJECT',
231
                                        'name' => '__Type',
232
                                        'fields' =>
233
                                            array (
234
                                                0 =>
235
                                                    array (
236
                                                        'name' => 'kind',
237
                                                        'args' =>
238
                                                            array (
239
                                                            ),
240
                                                        'type' =>
241
                                                            array (
242
                                                                'kind' => 'NON_NULL',
243
                                                                'name' => NULL,
244
                                                                'ofType' =>
245
                                                                    array (
246
                                                                        'kind' => 'ENUM',
247
                                                                        'name' => '__TypeKind',
248
                                                                    ),
249
                                                            ),
250
                                                        'isDeprecated' => false,
251
                                                        'deprecationReason' => NULL,
252
                                                    ),
253
                                                1 =>
254
                                                    array (
255
                                                        'name' => 'name',
256
                                                        'args' =>
257
                                                            array (
258
                                                            ),
259
                                                        'type' =>
260
                                                            array (
261
                                                                'kind' => 'SCALAR',
262
                                                                'name' => 'String',
263
                                                            ),
264
                                                        'isDeprecated' => false,
265
                                                        'deprecationReason' => NULL,
266
                                                    ),
267
                                                2 =>
268
                                                    array (
269
                                                        'name' => 'description',
270
                                                        'args' =>
271
                                                            array (
272
                                                            ),
273
                                                        'type' =>
274
                                                            array (
275
                                                                'kind' => 'SCALAR',
276
                                                                'name' => 'String',
277
                                                            ),
278
                                                        'isDeprecated' => false,
279
                                                        'deprecationReason' => NULL,
280
                                                    ),
281
                                                3 =>
282
                                                    array (
283
                                                        'name' => 'fields',
284
                                                        'args' =>
285
                                                            array (
286
                                                                0 =>
287
                                                                    array (
288
                                                                        'name' => 'includeDeprecated',
289
                                                                        'type' =>
290
                                                                            array (
291
                                                                                'kind' => 'SCALAR',
292
                                                                                'name' => 'Boolean',
293
                                                                            ),
294
                                                                        'defaultValue' => 'false',
295
                                                                    ),
296
                                                            ),
297
                                                        'type' =>
298
                                                            array (
299
                                                                'kind' => 'LIST',
300
                                                                'name' => NULL,
301
                                                                'ofType' =>
302
                                                                    array (
303
                                                                        'kind' => 'NON_NULL',
304
                                                                        'name' => NULL,
305
                                                                        'ofType' =>
306
                                                                            array (
307
                                                                                'kind' => 'OBJECT',
308
                                                                                'name' => '__Field',
309
                                                                            ),
310
                                                                    ),
311
                                                            ),
312
                                                        'isDeprecated' => false,
313
                                                        'deprecationReason' => NULL,
314
                                                    ),
315
                                                4 =>
316
                                                    array (
317
                                                        'name' => 'interfaces',
318
                                                        'args' =>
319
                                                            array (
320
                                                            ),
321
                                                        'type' =>
322
                                                            array (
323
                                                                'kind' => 'LIST',
324
                                                                'name' => NULL,
325
                                                                'ofType' =>
326
                                                                    array (
327
                                                                        'kind' => 'NON_NULL',
328
                                                                        'name' => NULL,
329
                                                                        'ofType' =>
330
                                                                            array (
331
                                                                                'kind' => 'OBJECT',
332
                                                                                'name' => '__Type',
333
                                                                            ),
334
                                                                    ),
335
                                                            ),
336
                                                        'isDeprecated' => false,
337
                                                        'deprecationReason' => NULL,
338
                                                    ),
339
                                                5 =>
340
                                                    array (
341
                                                        'name' => 'possibleTypes',
342
                                                        'args' =>
343
                                                            array (
344
                                                            ),
345
                                                        'type' =>
346
                                                            array (
347
                                                                'kind' => 'LIST',
348
                                                                'name' => NULL,
349
                                                                'ofType' =>
350
                                                                    array (
351
                                                                        'kind' => 'NON_NULL',
352
                                                                        'name' => NULL,
353
                                                                        'ofType' =>
354
                                                                            array (
355
                                                                                'kind' => 'OBJECT',
356
                                                                                'name' => '__Type',
357
                                                                            ),
358
                                                                    ),
359
                                                            ),
360
                                                        'isDeprecated' => false,
361
                                                        'deprecationReason' => NULL,
362
                                                    ),
363
                                                6 =>
364
                                                    array (
365
                                                        'name' => 'enumValues',
366
                                                        'args' =>
367
                                                            array (
368
                                                                0 =>
369
                                                                    array (
370
                                                                        'name' => 'includeDeprecated',
371
                                                                        'type' =>
372
                                                                            array (
373
                                                                                'kind' => 'SCALAR',
374
                                                                                'name' => 'Boolean',
375
                                                                            ),
376
                                                                        'defaultValue' => 'false',
377
                                                                    ),
378
                                                            ),
379
                                                        'type' =>
380
                                                            array (
381
                                                                'kind' => 'LIST',
382
                                                                'name' => NULL,
383
                                                                'ofType' =>
384
                                                                    array (
385
                                                                        'kind' => 'NON_NULL',
386
                                                                        'name' => NULL,
387
                                                                        'ofType' =>
388
                                                                            array (
389
                                                                                'kind' => 'OBJECT',
390
                                                                                'name' => '__EnumValue',
391
                                                                            ),
392
                                                                    ),
393
                                                            ),
394
                                                        'isDeprecated' => false,
395
                                                        'deprecationReason' => NULL,
396
                                                    ),
397
                                                7 =>
398
                                                    array (
399
                                                        'name' => 'inputFields',
400
                                                        'args' =>
401
                                                            array (
402
                                                            ),
403
                                                        'type' =>
404
                                                            array (
405
                                                                'kind' => 'LIST',
406
                                                                'name' => NULL,
407
                                                                'ofType' =>
408
                                                                    array (
409
                                                                        'kind' => 'NON_NULL',
410
                                                                        'name' => NULL,
411
                                                                        'ofType' =>
412
                                                                            array (
413
                                                                                'kind' => 'OBJECT',
414
                                                                                'name' => '__InputValue',
415
                                                                            ),
416
                                                                    ),
417
                                                            ),
418
                                                        'isDeprecated' => false,
419
                                                        'deprecationReason' => NULL,
420
                                                    ),
421
                                                8 =>
422
                                                    array (
423
                                                        'name' => 'ofType',
424
                                                        'args' =>
425
                                                            array (
426
                                                            ),
427
                                                        'type' =>
428
                                                            array (
429
                                                                'kind' => 'OBJECT',
430
                                                                'name' => '__Type',
431
                                                            ),
432
                                                        'isDeprecated' => false,
433
                                                        'deprecationReason' => NULL,
434
                                                    ),
435
                                            ),
436
                                        'inputFields' => NULL,
437
                                        'interfaces' =>
438
                                            array (
439
                                            ),
440
                                        'enumValues' => NULL,
441
                                        'possibleTypes' => NULL,
442
                                    ),
443
                                    array (
444
                                        'kind' => 'ENUM',
445
                                        'name' => '__TypeKind',
446
                                        'fields' => NULL,
447
                                        'inputFields' => NULL,
448
                                        'interfaces' => NULL,
449
                                        'enumValues' =>
450
                                            array (
451
                                                0 =>
452
                                                    array (
453
                                                        'name' => 'SCALAR',
454
                                                        'isDeprecated' => false,
455
                                                        'deprecationReason' => NULL,
456
                                                    ),
457
                                                1 =>
458
                                                    array (
459
                                                        'name' => 'OBJECT',
460
                                                        'isDeprecated' => false,
461
                                                        'deprecationReason' => NULL,
462
                                                    ),
463
                                                2 =>
464
                                                    array (
465
                                                        'name' => 'INTERFACE',
466
                                                        'isDeprecated' => false,
467
                                                        'deprecationReason' => NULL,
468
                                                    ),
469
                                                3 =>
470
                                                    array (
471
                                                        'name' => 'UNION',
472
                                                        'isDeprecated' => false,
473
                                                        'deprecationReason' => NULL,
474
                                                    ),
475
                                                4 =>
476
                                                    array (
477
                                                        'name' => 'ENUM',
478
                                                        'isDeprecated' => false,
479
                                                        'deprecationReason' => NULL,
480
                                                    ),
481
                                                5 =>
482
                                                    array (
483
                                                        'name' => 'INPUT_OBJECT',
484
                                                        'isDeprecated' => false,
485
                                                        'deprecationReason' => NULL,
486
                                                    ),
487
                                                6 =>
488
                                                    array (
489
                                                        'name' => 'LIST',
490
                                                        'isDeprecated' => false,
491
                                                        'deprecationReason' => NULL,
492
                                                    ),
493
                                                7 =>
494
                                                    array (
495
                                                        'name' => 'NON_NULL',
496
                                                        'isDeprecated' => false,
497
                                                        'deprecationReason' => NULL,
498
                                                    ),
499
                                            ),
500
                                        'possibleTypes' => NULL,
501
                                    ),
502
                                    array (
503
                                        'kind' => 'OBJECT',
504
                                        'name' => '__Field',
505
                                        'fields' =>
506
                                            array (
507
                                                0 =>
508
                                                    array (
509
                                                        'name' => 'name',
510
                                                        'args' =>
511
                                                            array (
512
                                                            ),
513
                                                        'type' =>
514
                                                            array (
515
                                                                'kind' => 'NON_NULL',
516
                                                                'name' => NULL,
517
                                                                'ofType' =>
518
                                                                    array (
519
                                                                        'kind' => 'SCALAR',
520
                                                                        'name' => 'String',
521
                                                                    ),
522
                                                            ),
523
                                                        'isDeprecated' => false,
524
                                                        'deprecationReason' => NULL,
525
                                                    ),
526
                                                1 =>
527
                                                    array (
528
                                                        'name' => 'description',
529
                                                        'args' =>
530
                                                            array (
531
                                                            ),
532
                                                        'type' =>
533
                                                            array (
534
                                                                'kind' => 'SCALAR',
535
                                                                'name' => 'String',
536
                                                            ),
537
                                                        'isDeprecated' => false,
538
                                                        'deprecationReason' => NULL,
539
                                                    ),
540
                                                2 =>
541
                                                    array (
542
                                                        'name' => 'args',
543
                                                        'args' =>
544
                                                            array (
545
                                                            ),
546
                                                        'type' =>
547
                                                            array (
548
                                                                'kind' => 'NON_NULL',
549
                                                                'name' => NULL,
550
                                                                'ofType' =>
551
                                                                    array (
552
                                                                        'kind' => 'LIST',
553
                                                                        'name' => NULL,
554
                                                                        'ofType' =>
555
                                                                            array (
556
                                                                                'kind' => 'NON_NULL',
557
                                                                                'name' => NULL,
558
                                                                                'ofType' =>
559
                                                                                    array (
560
                                                                                        'kind' => 'OBJECT',
561
                                                                                        'name' => '__InputValue',
562
                                                                                    ),
563
                                                                            ),
564
                                                                    ),
565
                                                            ),
566
                                                        'isDeprecated' => false,
567
                                                        'deprecationReason' => NULL,
568
                                                    ),
569
                                                3 =>
570
                                                    array (
571
                                                        'name' => 'type',
572
                                                        'args' =>
573
                                                            array (
574
                                                            ),
575
                                                        'type' =>
576
                                                            array (
577
                                                                'kind' => 'NON_NULL',
578
                                                                'name' => NULL,
579
                                                                'ofType' =>
580
                                                                    array (
581
                                                                        'kind' => 'OBJECT',
582
                                                                        'name' => '__Type',
583
                                                                    ),
584
                                                            ),
585
                                                        'isDeprecated' => false,
586
                                                        'deprecationReason' => NULL,
587
                                                    ),
588
                                                4 =>
589
                                                    array (
590
                                                        'name' => 'isDeprecated',
591
                                                        'args' =>
592
                                                            array (
593
                                                            ),
594
                                                        'type' =>
595
                                                            array (
596
                                                                'kind' => 'NON_NULL',
597
                                                                'name' => NULL,
598
                                                                'ofType' =>
599
                                                                    array (
600
                                                                        'kind' => 'SCALAR',
601
                                                                        'name' => 'Boolean',
602
                                                                    ),
603
                                                            ),
604
                                                        'isDeprecated' => false,
605
                                                        'deprecationReason' => NULL,
606
                                                    ),
607
                                                5 =>
608
                                                    array (
609
                                                        'name' => 'deprecationReason',
610
                                                        'args' =>
611
                                                            array (
612
                                                            ),
613
                                                        'type' =>
614
                                                            array (
615
                                                                'kind' => 'SCALAR',
616
                                                                'name' => 'String',
617
                                                            ),
618
                                                        'isDeprecated' => false,
619
                                                        'deprecationReason' => NULL,
620
                                                    ),
621
                                            ),
622
                                        'inputFields' => NULL,
623
                                        'interfaces' =>
624
                                            array (
625
                                            ),
626
                                        'enumValues' => NULL,
627
                                        'possibleTypes' => NULL,
628
                                    ),
629
                                    array (
630
                                        'kind' => 'OBJECT',
631
                                        'name' => '__InputValue',
632
                                        'fields' =>
633
                                            array (
634
                                                0 =>
635
                                                    array (
636
                                                        'name' => 'name',
637
                                                        'args' =>
638
                                                            array (
639
                                                            ),
640
                                                        'type' =>
641
                                                            array (
642
                                                                'kind' => 'NON_NULL',
643
                                                                'name' => NULL,
644
                                                                'ofType' =>
645
                                                                    array (
646
                                                                        'kind' => 'SCALAR',
647
                                                                        'name' => 'String',
648
                                                                    ),
649
                                                            ),
650
                                                        'isDeprecated' => false,
651
                                                        'deprecationReason' => NULL,
652
                                                    ),
653
                                                1 =>
654
                                                    array (
655
                                                        'name' => 'description',
656
                                                        'args' =>
657
                                                            array (
658
                                                            ),
659
                                                        'type' =>
660
                                                            array (
661
                                                                'kind' => 'SCALAR',
662
                                                                'name' => 'String',
663
                                                            ),
664
                                                        'isDeprecated' => false,
665
                                                        'deprecationReason' => NULL,
666
                                                    ),
667
                                                2 =>
668
                                                    array (
669
                                                        'name' => 'type',
670
                                                        'args' =>
671
                                                            array (
672
                                                            ),
673
                                                        'type' =>
674
                                                            array (
675
                                                                'kind' => 'NON_NULL',
676
                                                                'name' => NULL,
677
                                                                'ofType' =>
678
                                                                    array (
679
                                                                        'kind' => 'OBJECT',
680
                                                                        'name' => '__Type',
681
                                                                    ),
682
                                                            ),
683
                                                        'isDeprecated' => false,
684
                                                        'deprecationReason' => NULL,
685
                                                    ),
686
                                                3 =>
687
                                                    array (
688
                                                        'name' => 'defaultValue',
689
                                                        'args' =>
690
                                                            array (
691
                                                            ),
692
                                                        'type' =>
693
                                                            array (
694
                                                                'kind' => 'SCALAR',
695
                                                                'name' => 'String',
696
                                                            ),
697
                                                        'isDeprecated' => false,
698
                                                        'deprecationReason' => NULL,
699
                                                    ),
700
                                            ),
701
                                        'inputFields' => NULL,
702
                                        'interfaces' =>
703
                                            array (
704
                                            ),
705
                                        'enumValues' => NULL,
706
                                        'possibleTypes' => NULL,
707
                                    ),
708
                                    array (
709
                                        'kind' => 'OBJECT',
710
                                        'name' => '__EnumValue',
711
                                        'fields' =>
712
                                            array (
713
                                                0 =>
714
                                                    array (
715
                                                        'name' => 'name',
716
                                                        'args' =>
717
                                                            array (
718
                                                            ),
719
                                                        'type' =>
720
                                                            array (
721
                                                                'kind' => 'NON_NULL',
722
                                                                'name' => NULL,
723
                                                                'ofType' =>
724
                                                                    array (
725
                                                                        'kind' => 'SCALAR',
726
                                                                        'name' => 'String',
727
                                                                    ),
728
                                                            ),
729
                                                        'isDeprecated' => false,
730
                                                        'deprecationReason' => NULL,
731
                                                    ),
732
                                                1 =>
733
                                                    array (
734
                                                        'name' => 'description',
735
                                                        'args' =>
736
                                                            array (
737
                                                            ),
738
                                                        'type' =>
739
                                                            array (
740
                                                                'kind' => 'SCALAR',
741
                                                                'name' => 'String',
742
                                                            ),
743
                                                        'isDeprecated' => false,
744
                                                        'deprecationReason' => NULL,
745
                                                    ),
746
                                                2 =>
747
                                                    array (
748
                                                        'name' => 'isDeprecated',
749
                                                        'args' =>
750
                                                            array (
751
                                                            ),
752
                                                        'type' =>
753
                                                            array (
754
                                                                'kind' => 'NON_NULL',
755
                                                                'name' => NULL,
756
                                                                'ofType' =>
757
                                                                    array (
758
                                                                        'kind' => 'SCALAR',
759
                                                                        'name' => 'Boolean',
760
                                                                    ),
761
                                                            ),
762
                                                        'isDeprecated' => false,
763
                                                        'deprecationReason' => NULL,
764
                                                    ),
765
                                                3 =>
766
                                                    array (
767
                                                        'name' => 'deprecationReason',
768
                                                        'args' =>
769
                                                            array (
770
                                                            ),
771
                                                        'type' =>
772
                                                            array (
773
                                                                'kind' => 'SCALAR',
774
                                                                'name' => 'String',
775
                                                            ),
776
                                                        'isDeprecated' => false,
777
                                                        'deprecationReason' => NULL,
778
                                                    ),
779
                                            ),
780
                                        'inputFields' => NULL,
781
                                        'interfaces' =>
782
                                            array (
783
                                            ),
784
                                        'enumValues' => NULL,
785
                                        'possibleTypes' => NULL,
786
                                    ),
787
                                    array (
788
                                        'kind' => 'OBJECT',
789
                                        'name' => '__Directive',
790
                                        'fields' =>
791
                                            array (
792
                                                0 =>
793
                                                    array (
794
                                                        'name' => 'name',
795
                                                        'args' =>
796
                                                            array (
797
                                                            ),
798
                                                        'type' =>
799
                                                            array (
800
                                                                'kind' => 'NON_NULL',
801
                                                                'name' => NULL,
802
                                                                'ofType' =>
803
                                                                    array (
804
                                                                        'kind' => 'SCALAR',
805
                                                                        'name' => 'String',
806
                                                                    ),
807
                                                            ),
808
                                                        'isDeprecated' => false,
809
                                                        'deprecationReason' => NULL,
810
                                                    ),
811
                                                1 =>
812
                                                    array (
813
                                                        'name' => 'description',
814
                                                        'args' =>
815
                                                            array (
816
                                                            ),
817
                                                        'type' =>
818
                                                            array (
819
                                                                'kind' => 'SCALAR',
820
                                                                'name' => 'String',
821
                                                            ),
822
                                                        'isDeprecated' => false,
823
                                                        'deprecationReason' => NULL,
824
                                                    ),
825
                                                2 =>
826
                                                    array (
827
                                                        'name' => 'locations',
828
                                                        'args' =>
829
                                                            array (
830
                                                            ),
831
                                                        'type' =>
832
                                                            array (
833
                                                                'kind' => 'NON_NULL',
834
                                                                'name' => NULL,
835
                                                                'ofType' =>
836
                                                                    array (
837
                                                                        'kind' => 'LIST',
838
                                                                        'name' => NULL,
839
                                                                        'ofType' =>
840
                                                                            array (
841
                                                                                'kind' => 'NON_NULL',
842
                                                                                'name' => NULL,
843
                                                                                'ofType' =>
844
                                                                                    array (
845
                                                                                        'kind' => 'ENUM',
846
                                                                                        'name' => '__DirectiveLocation',
847
                                                                                    ),
848
                                                                            ),
849
                                                                    ),
850
                                                            ),
851
                                                        'isDeprecated' => false,
852
                                                        'deprecationReason' => NULL,
853
                                                    ),
854
                                                3 =>
855
                                                    array (
856
                                                        'name' => 'args',
857
                                                        'args' =>
858
                                                            array (
859
                                                            ),
860
                                                        'type' =>
861
                                                            array (
862
                                                                'kind' => 'NON_NULL',
863
                                                                'name' => NULL,
864
                                                                'ofType' =>
865
                                                                    array (
866
                                                                        'kind' => 'LIST',
867
                                                                        'name' => NULL,
868
                                                                        'ofType' =>
869
                                                                            array (
870
                                                                                'kind' => 'NON_NULL',
871
                                                                                'name' => NULL,
872
                                                                                'ofType' =>
873
                                                                                    array (
874
                                                                                        'kind' => 'OBJECT',
875
                                                                                        'name' => '__InputValue',
876
                                                                                    ),
877
                                                                            ),
878
                                                                    ),
879
                                                            ),
880
                                                        'isDeprecated' => false,
881
                                                        'deprecationReason' => NULL,
882
                                                    ),
883
                                                4 =>
884
                                                    array (
885
                                                        'name' => 'onOperation',
886
                                                        'args' =>
887
                                                            array (
888
                                                            ),
889
                                                        'type' =>
890
                                                            array (
891
                                                                'kind' => 'NON_NULL',
892
                                                                'name' => NULL,
893
                                                                'ofType' =>
894
                                                                    array (
895
                                                                        'kind' => 'SCALAR',
896
                                                                        'name' => 'Boolean',
897
                                                                    ),
898
                                                            ),
899
                                                        'isDeprecated' => true,
900
                                                        'deprecationReason' => 'Use `locations`.',
901
                                                    ),
902
                                                5 =>
903
                                                    array (
904
                                                        'name' => 'onFragment',
905
                                                        'args' =>
906
                                                            array (
907
                                                            ),
908
                                                        'type' =>
909
                                                            array (
910
                                                                'kind' => 'NON_NULL',
911
                                                                'name' => NULL,
912
                                                                'ofType' =>
913
                                                                    array (
914
                                                                        'kind' => 'SCALAR',
915
                                                                        'name' => 'Boolean',
916
                                                                    ),
917
                                                            ),
918
                                                        'isDeprecated' => true,
919
                                                        'deprecationReason' => 'Use `locations`.',
920
                                                    ),
921
                                                6 =>
922
                                                    array (
923
                                                        'name' => 'onField',
924
                                                        'args' =>
925
                                                            array (
926
                                                            ),
927
                                                        'type' =>
928
                                                            array (
929
                                                                'kind' => 'NON_NULL',
930
                                                                'name' => NULL,
931
                                                                'ofType' =>
932
                                                                    array (
933
                                                                        'kind' => 'SCALAR',
934
                                                                        'name' => 'Boolean',
935
936
                                                                    ),
937
                                                            ),
938
                                                        'isDeprecated' => true,
939
                                                        'deprecationReason' => 'Use `locations`.',
940
                                                    ),
941
                                            ),
942
                                        'inputFields' => NULL,
943
                                        'interfaces' =>
944
                                            array (
945
                                            ),
946
                                        'enumValues' => NULL,
947
                                        'possibleTypes' => NULL,
948
                                    ),
949
                                    array (
950
                                        'kind' => 'ENUM',
951
                                        'name' => '__DirectiveLocation',
952
                                        'fields' => NULL,
953
                                        'inputFields' => NULL,
954
                                        'interfaces' => NULL,
955
                                        'enumValues' =>
956
                                            array (
957
                                                0 =>
958
                                                    array (
959
                                                        'name' => 'QUERY',
960
                                                        'isDeprecated' => false,
961
                                                        'deprecationReason' => null
962
                                                    ),
963
                                                1 =>
964
                                                    array (
965
                                                        'name' => 'MUTATION',
966
                                                        'isDeprecated' => false,
967
                                                        'deprecationReason' => null
968
                                                    ),
969
                                                2 =>
970
                                                    array (
971
                                                        'name' => 'SUBSCRIPTION',
972
                                                        'isDeprecated' => false,
973
                                                        'deprecationReason' => null
974
                                                    ),
975
                                                3 =>
976
                                                    array (
977
                                                        'name' => 'FIELD',
978
                                                        'isDeprecated' => false,
979
                                                        'deprecationReason' => null
980
                                                    ),
981
                                                4 =>
982
                                                    array (
983
                                                        'name' => 'FRAGMENT_DEFINITION',
984
                                                        'isDeprecated' => false,
985
                                                        'deprecationReason' => null
986
                                                    ),
987
                                                5 =>
988
                                                    array (
989
                                                        'name' => 'FRAGMENT_SPREAD',
990
                                                        'isDeprecated' => false,
991
                                                        'deprecationReason' => null
992
                                                    ),
993
                                                6 =>
994
                                                    array (
995
                                                        'name' => 'INLINE_FRAGMENT',
996
                                                        'isDeprecated' => false,
997
                                                        'deprecationReason' => null
998
                                                    ),
999
                                            ),
1000
                                        'possibleTypes' => NULL,
1001
                                    ),
1002
                                ),
1003
                            'directives' =>
1004
                                array (
1005
                                    0 =>
1006
                                        array (
1007
                                            'name' => 'include',
1008
                                            'locations' =>
1009
                                                array (
1010
                                                    0 => 'FIELD',
1011
                                                    1 => 'FRAGMENT_SPREAD',
1012
                                                    2 => 'INLINE_FRAGMENT',
1013
                                                ),
1014
                                            'args' =>
1015
                                                array (
1016
                                                    0 =>
1017
                                                        array (
1018
                                                            'defaultValue' => NULL,
1019
                                                            'name' => 'if',
1020
                                                            'type' =>
1021
                                                                array (
1022
                                                                    'kind' => 'NON_NULL',
1023
                                                                    'name' => NULL,
1024
                                                                    'ofType' =>
1025
                                                                        array (
1026
                                                                            'kind' => 'SCALAR',
1027
                                                                            'name' => 'Boolean',
1028
                                                                        ),
1029
                                                                ),
1030
                                                        ),
1031
                                                ),
1032
                                        ),
1033
                                    1 =>
1034
                                        array (
1035
                                            'name' => 'skip',
1036
                                            'locations' =>
1037
                                                array (
1038
                                                    0 => 'FIELD',
1039
                                                    1 => 'FRAGMENT_SPREAD',
1040
                                                    2 => 'INLINE_FRAGMENT',
1041
                                                ),
1042
                                            'args' =>
1043
                                                array (
1044
                                                    0 =>
1045
                                                        array (
1046
                                                            'defaultValue' => NULL,
1047
                                                            'name' => 'if',
1048
                                                            'type' =>
1049
                                                                array (
1050
                                                                    'kind' => 'NON_NULL',
1051
                                                                    'name' => NULL,
1052
                                                                    'ofType' =>
1053
                                                                        array (
1054
                                                                            'kind' => 'SCALAR',
1055
                                                                            'name' => 'Boolean',
1056
                                                                        ),
1057
                                                                ),
1058
                                                        ),
1059
                                                ),
1060
                                        ),
1061
                                ),
1062
                        ),
1063
                )
1064
        );
1065
1066
        $actual = GraphQL::executeQuery($emptySchema, $request)->toArray();
1067
1068
        // $this->assertEquals($expected, $actual);
1069
        $this->assertArraySubset($expected, $actual);
1070
    }
1071
1072
    /**
1073
     * @see it('introspects on input object')
1074
     */
1075
    function testIntrospectsOnInputObject()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1076
    {
1077
        $TestInputObject = new InputObjectType([
1078
            'name' => 'TestInputObject',
1079
            'fields' => [
1080
                'a' => ['type' => Type::string(), 'defaultValue' => "tes\t de\fault"],
1081
                'b' => ['type' => Type::listOf(Type::string())],
1082
                'c' => ['type' => Type::string(), 'defaultValue' => null ]
1083
            ]
1084
        ]);
1085
1086
        $TestType = new ObjectType([
1087
            'name' => 'TestType',
1088
            'fields' => [
1089
                'field' => [
1090
                    'type' => Type::string(),
1091
                    'args' => ['complex' => ['type' => $TestInputObject]],
1092
                    'resolve' => function ($_, $args) {
1093
                        return json_encode($args['complex']);
1094
                    }
1095
                ]
1096
            ]
1097
        ]);
1098
1099
        $schema = new Schema(['query' => $TestType]);
1100
        $request = '
1101
          {
1102
            __type(name: "TestInputObject") {
1103
              kind
1104
              name
1105
              inputFields {
1106
                name
1107
                type { ...TypeRef }
1108
                defaultValue
1109
              }
1110
            }
1111
          }
1112
1113
          fragment TypeRef on __Type {
1114
            kind
1115
            name
1116
            ofType {
1117
              kind
1118
              name
1119
              ofType {
1120
                kind
1121
                name
1122
                ofType {
1123
                  kind
1124
                  name
1125
                }
1126
              }
1127
            }
1128
          }
1129
        ';
1130
1131
1132
        $expectedFragment = [
1133
            'kind' => 'INPUT_OBJECT',
1134
            'name' => 'TestInputObject',
1135
            'inputFields' => [
1136
                [
1137
                    'name' => 'a',
1138
                    'type' => [
1139
                        'kind' => 'SCALAR',
1140
                        'name' => 'String',
1141
                        'ofType' => null
1142
                    ],
1143
                    'defaultValue' => '"tes\t de\fault"'
1144
                ],
1145
                [
1146
                    'name' => 'b',
1147
                    'type' => [
1148
                        'kind' => 'LIST',
1149
                        'name' => null,
1150
                        'ofType' => ['kind' => 'SCALAR', 'name' => 'String', 'ofType' => null]
1151
                    ],
1152
                    'defaultValue' => null
1153
                ],
1154
                [
1155
                    'name' => 'c',
1156
                    'type' => [
1157
                        'kind' => 'SCALAR',
1158
                        'name' => 'String',
1159
                        'ofType' => null
1160
                    ],
1161
                    'defaultValue' => 'null' // defaultValue was set (even if it was set to null)
1162
                ]
1163
            ]
1164
        ];
1165
1166
        $result = GraphQL::executeQuery($schema, $request)->toArray();
1167
        $result = $result['data']['__type'];
1168
        $this->assertEquals($expectedFragment, $result);
1169
    }
1170
1171
    /**
1172
     * @see it('supports the __type root field')
1173
     */
1174
    public function testSupportsTheTypeRootField() : void
1175
    {
1176
        $TestType = new ObjectType([
1177
            'name' => 'TestType',
1178
            'fields' => [
1179
                'testField' => [
1180
                    'type' => Type::string(),
1181
                ]
1182
            ]
1183
        ]);
1184
1185
        $schema = new Schema(['query' => $TestType]);
1186
        $request = '
1187
          {
1188
            __type(name: "TestType") {
1189
              name
1190
            }
1191
          }
1192
        ';
1193
1194
        $expected = ['data' => [
1195
            '__type' => [
1196
                'name' => 'TestType'
1197
            ]
1198
        ]];
1199
1200
        $this->assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1201
    }
1202
1203
    /**
1204
     * @see it('identifies deprecated fields')
1205
     */
1206
    public function testIdentifiesDeprecatedFields() : void
1207
    {
1208
1209
        $TestType = new ObjectType([
1210
            'name' => 'TestType',
1211
            'fields' => [
1212
                'nonDeprecated' => [
1213
                    'type' => Type::string(),
1214
                ],
1215
                'deprecated' => [
1216
                    'type' => Type::string(),
1217
                    'deprecationReason' => 'Removed in 1.0'
1218
                ]
1219
            ]
1220
        ]);
1221
1222
        $schema = new Schema(['query' => $TestType]);
1223
        $request = '
1224
          {
1225
            __type(name: "TestType") {
1226
              name
1227
              fields(includeDeprecated: true) {
1228
                name
1229
                isDeprecated,
1230
                deprecationReason
1231
              }
1232
            }
1233
          }
1234
        ';
1235
1236
        $expected = [
1237
            'data' => [
1238
                '__type' => [
1239
                    'name' => 'TestType',
1240
                    'fields' => [
1241
                        [
1242
                            'name' => 'nonDeprecated',
1243
                            'isDeprecated' => false,
1244
                            'deprecationReason' => null
1245
                        ],
1246
                        [
1247
                            'name' => 'deprecated',
1248
                            'isDeprecated' => true,
1249
                            'deprecationReason' => 'Removed in 1.0'
1250
                        ]
1251
                    ]
1252
                ]
1253
            ]
1254
        ];
1255
        $this->assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1256
    }
1257
1258
    /**
1259
     * @see it('respects the includeDeprecated parameter for fields')
1260
     */
1261
    public function testRespectsTheIncludeDeprecatedParameterForFields() : void
1262
    {
1263
        $TestType = new ObjectType([
1264
            'name' => 'TestType',
1265
            'fields' => [
1266
                'nonDeprecated' => [
1267
                    'type' => Type::string(),
1268
                ],
1269
                'deprecated' => [
1270
                    'type' => Type::string(),
1271
                    'deprecationReason' => 'Removed in 1.0'
1272
                ]
1273
            ]
1274
        ]);
1275
1276
        $schema = new Schema(['query' => $TestType]);
1277
        $request = '
1278
      {
1279
        __type(name: "TestType") {
1280
          name
1281
          trueFields: fields(includeDeprecated: true) {
1282
            name
1283
          }
1284
          falseFields: fields(includeDeprecated: false) {
1285
            name
1286
          }
1287
          omittedFields: fields {
1288
            name
1289
          }
1290
        }
1291
      }
1292
        ';
1293
1294
        $expected = [
1295
            'data' => [
1296
                '__type' => [
1297
                    'name' => 'TestType',
1298
                    'trueFields' => [
1299
                        [
1300
                            'name' => 'nonDeprecated',
1301
                        ],
1302
                        [
1303
                            'name' => 'deprecated',
1304
                        ]
1305
                    ],
1306
                    'falseFields' => [
1307
                        [
1308
                            'name' => 'nonDeprecated',
1309
                        ]
1310
                    ],
1311
                    'omittedFields' => [
1312
                        [
1313
                            'name' => 'nonDeprecated',
1314
                        ]
1315
                    ],
1316
                ]
1317
            ]
1318
        ];
1319
1320
        $this->assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1321
    }
1322
1323
    /**
1324
     * @see it('identifies deprecated enum values')
1325
     */
1326
    public function testIdentifiesDeprecatedEnumValues() : void
1327
    {
1328
        $TestEnum = new EnumType([
1329
            'name' => 'TestEnum',
1330
            'values' => [
1331
                'NONDEPRECATED' => ['value' => 0],
1332
                'DEPRECATED' => ['value' => 1, 'deprecationReason' => 'Removed in 1.0'],
1333
                'ALSONONDEPRECATED' => ['value' => 2]
1334
            ]
1335
        ]);
1336
1337
        $TestType = new ObjectType([
1338
            'name' => 'TestType',
1339
            'fields' => [
1340
                'testEnum' => [
1341
                    'type' => $TestEnum,
1342
                ],
1343
            ]
1344
        ]);
1345
1346
        $schema = new Schema(['query' => $TestType]);
1347
        $request = '
1348
          {
1349
            __type(name: "TestEnum") {
1350
              name
1351
              enumValues(includeDeprecated: true) {
1352
                name
1353
                isDeprecated,
1354
                deprecationReason
1355
              }
1356
            }
1357
          }
1358
        ';
1359
1360
        $expected = [
1361
            'data' => [
1362
                '__type' => [
1363
                    'name' => 'TestEnum',
1364
                    'enumValues' => [
1365
                        [
1366
                            'name' => 'NONDEPRECATED',
1367
                            'isDeprecated' => false,
1368
                            'deprecationReason' => null
1369
                        ],
1370
                        [
1371
                            'name' => 'DEPRECATED',
1372
                            'isDeprecated' => true,
1373
                            'deprecationReason' => 'Removed in 1.0'
1374
                        ],
1375
                        [
1376
                            'name' => 'ALSONONDEPRECATED',
1377
                            'isDeprecated' => false,
1378
                            'deprecationReason' => null
1379
                        ]
1380
                    ]
1381
                ]
1382
            ]
1383
        ];
1384
        $this->assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1385
    }
1386
1387
    /**
1388
     * @see it('respects the includeDeprecated parameter for enum values')
1389
     */
1390
    public function testRespectsTheIncludeDeprecatedParameterForEnumValues() : void
1391
    {
1392
        $TestEnum = new EnumType([
1393
            'name' => 'TestEnum',
1394
            'values' => [
1395
                'NONDEPRECATED' => ['value' => 0],
1396
                'DEPRECATED' => ['value' => 1, 'deprecationReason' => 'Removed in 1.0'],
1397
                'ALSONONDEPRECATED' => ['value' => 2]
1398
            ]
1399
        ]);
1400
1401
        $TestType = new ObjectType([
1402
            'name' => 'TestType',
1403
            'fields' => [
1404
                'testEnum' => [
1405
                    'type' => $TestEnum,
1406
                ],
1407
            ]
1408
        ]);
1409
1410
        $schema = new Schema(['query' => $TestType]);
1411
        $request = '
1412
          {
1413
            __type(name: "TestEnum") {
1414
              name
1415
              trueValues: enumValues(includeDeprecated: true) {
1416
                name
1417
              }
1418
              falseValues: enumValues(includeDeprecated: false) {
1419
                name
1420
              }
1421
              omittedValues: enumValues {
1422
                name
1423
              }
1424
            }
1425
          }
1426
        ';
1427
        $expected = [
1428
            'data' => [
1429
                '__type' => [
1430
                    'name' => 'TestEnum',
1431
                    'trueValues' => [
1432
                        ['name' => 'NONDEPRECATED'],
1433
                        ['name' => 'DEPRECATED'],
1434
                        ['name' => 'ALSONONDEPRECATED']
1435
                    ],
1436
                    'falseValues' => [
1437
                        ['name' => 'NONDEPRECATED'],
1438
                        ['name' => 'ALSONONDEPRECATED']
1439
                    ],
1440
                    'omittedValues' => [
1441
                        ['name' => 'NONDEPRECATED'],
1442
                        ['name' => 'ALSONONDEPRECATED']
1443
                    ],
1444
                ]
1445
            ]
1446
        ];
1447
        $this->assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1448
    }
1449
1450
    /**
1451
     * @see it('fails as expected on the __type root field without an arg')
1452
     */
1453
    public function testFailsAsExpectedOnTheTypeRootFieldWithoutAnArg() : void
1454
    {
1455
        $TestType = new ObjectType([
1456
            'name' => 'TestType',
1457
            'fields' => [
1458
                'testField' => [
1459
                    'type' => Type::string(),
1460
                ]
1461
            ]
1462
        ]);
1463
1464
        $schema = new Schema(['query' => $TestType]);
1465
        $request = '
1466
      {
1467
        __type {
1468
          name
1469
        }
1470
      }
1471
    ';
1472
        $expected = [
1473
            'errors' => [
1474
                FormattedError::create(
0 ignored issues
show
Deprecated Code introduced by
The function GraphQL\Error\FormattedError::create() has been deprecated: as of v0.8.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1474
                /** @scrutinizer ignore-deprecated */ FormattedError::create(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1475
                    ProvidedNonNullArguments::missingFieldArgMessage('__type', 'name', 'String!'), [new SourceLocation(3, 9)]
1476
                )
1477
            ]
1478
        ];
1479
        $this->assertArraySubset($expected, GraphQL::executeQuery($schema, $request)->toArray());
1480
    }
1481
1482
    /**
1483
     * @see it('exposes descriptions on types and fields')
1484
     */
1485
    public function testExposesDescriptionsOnTypesAndFields() : void
1486
    {
1487
        $QueryRoot = new ObjectType([
1488
            'name' => 'QueryRoot',
1489
            'fields' => ['a' => Type::string()]
1490
        ]);
1491
1492
        $schema = new Schema(['query' => $QueryRoot]);
1493
        $request = '
1494
      {
1495
        schemaType: __type(name: "__Schema") {
1496
          name,
1497
          description,
1498
          fields {
1499
            name,
1500
            description
1501
          }
1502
        }
1503
      }
1504
        ';
1505
        $expected = [
1506
            'data' => [
1507
                'schemaType' => [
1508
                    'name' => '__Schema',
1509
                    'description' => 'A GraphQL Schema defines the capabilities of a ' .
1510
                        'GraphQL server. It exposes all available types and ' .
1511
                        'directives on the server, as well as the entry ' .
1512
                        'points for query, mutation, and subscription operations.',
1513
                    'fields' => [
1514
                        [
1515
                            'name' => 'types',
1516
                            'description' => 'A list of all types supported by this server.'
1517
                        ],
1518
                        [
1519
                            'name' => 'queryType',
1520
                            'description' => 'The type that query operations will be rooted at.'
1521
                        ],
1522
                        [
1523
                            'name' => 'mutationType',
1524
                            'description' => 'If this server supports mutation, the type that ' .
1525
                                'mutation operations will be rooted at.'
1526
                        ],
1527
                        [
1528
                            'name' => 'subscriptionType',
1529
                            'description' => 'If this server support subscription, the type that subscription operations will be rooted at.'
1530
                        ],
1531
                        [
1532
                            'name' => 'directives',
1533
                            'description' => 'A list of all directives supported by this server.'
1534
                        ]
1535
                    ]
1536
                ]
1537
            ]
1538
        ];
1539
        $this->assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1540
    }
1541
1542
    /**
1543
     * @see it('exposes descriptions on enums')
1544
     */
1545
    public function testExposesDescriptionsOnEnums() : void
1546
    {
1547
        $QueryRoot = new ObjectType([
1548
            'name' => 'QueryRoot',
1549
            'fields' => ['a' => Type::string()]
1550
        ]);
1551
1552
        $schema = new Schema(['query' => $QueryRoot]);
1553
        $request = '
1554
      {
1555
        typeKindType: __type(name: "__TypeKind") {
1556
          name,
1557
          description,
1558
          enumValues {
1559
            name,
1560
            description
1561
          }
1562
        }
1563
      }
1564
    ';
1565
        $expected = [
1566
            'data' => [
1567
                'typeKindType' => [
1568
                    'name' => '__TypeKind',
1569
                    'description' => 'An enum describing what kind of type a given `__Type` is.',
1570
                    'enumValues' => [
1571
                        [
1572
                            'description' => 'Indicates this type is a scalar.',
1573
                            'name' => 'SCALAR'
1574
                        ],
1575
                        [
1576
                            'description' => 'Indicates this type is an object. ' .
1577
                                '`fields` and `interfaces` are valid fields.',
1578
                            'name' => 'OBJECT'
1579
                        ],
1580
                        [
1581
                            'description' => 'Indicates this type is an interface. ' .
1582
                                '`fields` and `possibleTypes` are valid fields.',
1583
                            'name' => 'INTERFACE'
1584
                        ],
1585
                        [
1586
                            'description' => 'Indicates this type is a union. ' .
1587
                                '`possibleTypes` is a valid field.',
1588
                            'name' => 'UNION'
1589
                        ],
1590
                        [
1591
                            'description' => 'Indicates this type is an enum. ' .
1592
                                '`enumValues` is a valid field.',
1593
                            'name' => 'ENUM'
1594
                        ],
1595
                        [
1596
                            'description' => 'Indicates this type is an input object. ' .
1597
                                '`inputFields` is a valid field.',
1598
                            'name' => 'INPUT_OBJECT'
1599
                        ],
1600
                        [
1601
                            'description' => 'Indicates this type is a list. ' .
1602
                                '`ofType` is a valid field.',
1603
                            'name' => 'LIST'
1604
                        ],
1605
                        [
1606
                            'description' => 'Indicates this type is a non-null. ' .
1607
                                '`ofType` is a valid field.',
1608
                            'name' => 'NON_NULL'
1609
                        ]
1610
                    ]
1611
                ]
1612
            ]
1613
        ];
1614
1615
        $this->assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1616
    }
1617
}
1618