Failed Conditions
Push — master ( bf4e7d...c70528 )
by Vladimir
09:31
created

testFailsAsExpectedOnTheTypeRootFieldWithoutAnArg()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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

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

1030
        /** @scrutinizer ignore-deprecated */ self::assertArraySubset($expected, $actual);

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...
1031
    }
1032
1033
    /**
1034
     * @see it('introspects on input object')
1035
     */
1036
    public function testIntrospectsOnInputObject() : void
1037
    {
1038
        $TestInputObject = new InputObjectType([
1039
            'name'   => 'TestInputObject',
1040
            'fields' => [
1041
                'a' => ['type' => Type::string(), 'defaultValue' => "tes\t de\fault"],
1042
                'b' => ['type' => Type::listOf(Type::string())],
1043
                'c' => ['type' => Type::string(), 'defaultValue' => null],
1044
            ],
1045
        ]);
1046
1047
        $TestType = new ObjectType([
1048
            'name'   => 'TestType',
1049
            'fields' => [
1050
                'field' => [
1051
                    'type'    => Type::string(),
1052
                    'args'    => ['complex' => ['type' => $TestInputObject]],
1053
                    'resolve' => static function ($testType, $args) {
1054
                        return json_encode($args['complex']);
1055
                    },
1056
                ],
1057
            ],
1058
        ]);
1059
1060
        $schema  = new Schema(['query' => $TestType]);
1061
        $request = '
1062
          {
1063
            __type(name: "TestInputObject") {
1064
              kind
1065
              name
1066
              inputFields {
1067
                name
1068
                type { ...TypeRef }
1069
                defaultValue
1070
              }
1071
            }
1072
          }
1073
1074
          fragment TypeRef on __Type {
1075
            kind
1076
            name
1077
            ofType {
1078
              kind
1079
              name
1080
              ofType {
1081
                kind
1082
                name
1083
                ofType {
1084
                  kind
1085
                  name
1086
                }
1087
              }
1088
            }
1089
          }
1090
        ';
1091
1092
        $expectedFragment = [
1093
            'kind'        => 'INPUT_OBJECT',
1094
            'name'        => 'TestInputObject',
1095
            'inputFields' => [
1096
                [
1097
                    'name'         => 'a',
1098
                    'type'         => [
1099
                        'kind'   => 'SCALAR',
1100
                        'name'   => 'String',
1101
                        'ofType' => null,
1102
                    ],
1103
                    'defaultValue' => '"tes\t de\fault"',
1104
                ],
1105
                [
1106
                    'name'         => 'b',
1107
                    'type'         => [
1108
                        'kind'   => 'LIST',
1109
                        'name'   => null,
1110
                        'ofType' => ['kind' => 'SCALAR', 'name' => 'String', 'ofType' => null],
1111
                    ],
1112
                    'defaultValue' => null,
1113
                ],
1114
                [
1115
                    'name'         => 'c',
1116
                    'type'         => [
1117
                        'kind'   => 'SCALAR',
1118
                        'name'   => 'String',
1119
                        'ofType' => null,
1120
                    ],
1121
                    'defaultValue' => 'null',// defaultValue was set (even if it was set to null)
1122
                ],
1123
            ],
1124
        ];
1125
1126
        $result = GraphQL::executeQuery($schema, $request)->toArray();
1127
        $result = $result['data']['__type'];
1128
        self::assertEquals($expectedFragment, $result);
1129
    }
1130
1131
    /**
1132
     * @see it('supports the __type root field')
1133
     */
1134
    public function testSupportsTheTypeRootField() : void
1135
    {
1136
        $TestType = new ObjectType([
1137
            'name'   => 'TestType',
1138
            'fields' => [
1139
                'testField' => [
1140
                    'type' => Type::string(),
1141
                ],
1142
            ],
1143
        ]);
1144
1145
        $schema  = new Schema(['query' => $TestType]);
1146
        $request = '
1147
          {
1148
            __type(name: "TestType") {
1149
              name
1150
            }
1151
          }
1152
        ';
1153
1154
        $expected = [
1155
            'data' => [
1156
                '__type' => ['name' => 'TestType'],
1157
            ],
1158
        ];
1159
1160
        self::assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1161
    }
1162
1163
    /**
1164
     * @see it('identifies deprecated fields')
1165
     */
1166
    public function testIdentifiesDeprecatedFields() : void
1167
    {
1168
        $TestType = new ObjectType([
1169
            'name'   => 'TestType',
1170
            'fields' => [
1171
                'nonDeprecated' => [
1172
                    'type' => Type::string(),
1173
                ],
1174
                'deprecated'    => [
1175
                    'type'              => Type::string(),
1176
                    'deprecationReason' => 'Removed in 1.0',
1177
                ],
1178
            ],
1179
        ]);
1180
1181
        $schema  = new Schema(['query' => $TestType]);
1182
        $request = '
1183
          {
1184
            __type(name: "TestType") {
1185
              name
1186
              fields(includeDeprecated: true) {
1187
                name
1188
                isDeprecated,
1189
                deprecationReason
1190
              }
1191
            }
1192
          }
1193
        ';
1194
1195
        $expected = [
1196
            'data' => [
1197
                '__type' => [
1198
                    'name'   => 'TestType',
1199
                    'fields' => [
1200
                        [
1201
                            'name'              => 'nonDeprecated',
1202
                            'isDeprecated'      => false,
1203
                            'deprecationReason' => null,
1204
                        ],
1205
                        [
1206
                            'name'              => 'deprecated',
1207
                            'isDeprecated'      => true,
1208
                            'deprecationReason' => 'Removed in 1.0',
1209
                        ],
1210
                    ],
1211
                ],
1212
            ],
1213
        ];
1214
        self::assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1215
    }
1216
1217
    /**
1218
     * @see it('respects the includeDeprecated parameter for fields')
1219
     */
1220
    public function testRespectsTheIncludeDeprecatedParameterForFields() : void
1221
    {
1222
        $TestType = new ObjectType([
1223
            'name'   => 'TestType',
1224
            'fields' => [
1225
                'nonDeprecated' => [
1226
                    'type' => Type::string(),
1227
                ],
1228
                'deprecated'    => [
1229
                    'type'              => Type::string(),
1230
                    'deprecationReason' => 'Removed in 1.0',
1231
                ],
1232
            ],
1233
        ]);
1234
1235
        $schema  = new Schema(['query' => $TestType]);
1236
        $request = '
1237
      {
1238
        __type(name: "TestType") {
1239
          name
1240
          trueFields: fields(includeDeprecated: true) {
1241
            name
1242
          }
1243
          falseFields: fields(includeDeprecated: false) {
1244
            name
1245
          }
1246
          omittedFields: fields {
1247
            name
1248
          }
1249
        }
1250
      }
1251
        ';
1252
1253
        $expected = [
1254
            'data' => [
1255
                '__type' => [
1256
                    'name'          => 'TestType',
1257
                    'trueFields'    => [
1258
                        ['name' => 'nonDeprecated'],
1259
                        ['name' => 'deprecated'],
1260
                    ],
1261
                    'falseFields'   => [
1262
                        ['name' => 'nonDeprecated'],
1263
                    ],
1264
                    'omittedFields' => [
1265
                        ['name' => 'nonDeprecated'],
1266
                    ],
1267
                ],
1268
            ],
1269
        ];
1270
1271
        self::assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1272
    }
1273
1274
    /**
1275
     * @see it('identifies deprecated enum values')
1276
     */
1277
    public function testIdentifiesDeprecatedEnumValues() : void
1278
    {
1279
        $TestEnum = new EnumType([
1280
            'name'   => 'TestEnum',
1281
            'values' => [
1282
                'NONDEPRECATED'     => ['value' => 0],
1283
                'DEPRECATED'        => ['value' => 1, 'deprecationReason' => 'Removed in 1.0'],
1284
                'ALSONONDEPRECATED' => ['value' => 2],
1285
            ],
1286
        ]);
1287
1288
        $TestType = new ObjectType([
1289
            'name'   => 'TestType',
1290
            'fields' => [
1291
                'testEnum' => ['type' => $TestEnum],
1292
            ],
1293
        ]);
1294
1295
        $schema  = new Schema(['query' => $TestType]);
1296
        $request = '
1297
          {
1298
            __type(name: "TestEnum") {
1299
              name
1300
              enumValues(includeDeprecated: true) {
1301
                name
1302
                isDeprecated,
1303
                deprecationReason
1304
              }
1305
            }
1306
          }
1307
        ';
1308
1309
        $expected = [
1310
            'data' => [
1311
                '__type' => [
1312
                    'name'       => 'TestEnum',
1313
                    'enumValues' => [
1314
                        [
1315
                            'name'              => 'NONDEPRECATED',
1316
                            'isDeprecated'      => false,
1317
                            'deprecationReason' => null,
1318
                        ],
1319
                        [
1320
                            'name'              => 'DEPRECATED',
1321
                            'isDeprecated'      => true,
1322
                            'deprecationReason' => 'Removed in 1.0',
1323
                        ],
1324
                        [
1325
                            'name'              => 'ALSONONDEPRECATED',
1326
                            'isDeprecated'      => false,
1327
                            'deprecationReason' => null,
1328
                        ],
1329
                    ],
1330
                ],
1331
            ],
1332
        ];
1333
        self::assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1334
    }
1335
1336
    /**
1337
     * @see it('respects the includeDeprecated parameter for enum values')
1338
     */
1339
    public function testRespectsTheIncludeDeprecatedParameterForEnumValues() : void
1340
    {
1341
        $TestEnum = new EnumType([
1342
            'name'   => 'TestEnum',
1343
            'values' => [
1344
                'NONDEPRECATED'     => ['value' => 0],
1345
                'DEPRECATED'        => ['value' => 1, 'deprecationReason' => 'Removed in 1.0'],
1346
                'ALSONONDEPRECATED' => ['value' => 2],
1347
            ],
1348
        ]);
1349
1350
        $TestType = new ObjectType([
1351
            'name'   => 'TestType',
1352
            'fields' => [
1353
                'testEnum' => ['type' => $TestEnum],
1354
            ],
1355
        ]);
1356
1357
        $schema   = new Schema(['query' => $TestType]);
1358
        $request  = '
1359
          {
1360
            __type(name: "TestEnum") {
1361
              name
1362
              trueValues: enumValues(includeDeprecated: true) {
1363
                name
1364
              }
1365
              falseValues: enumValues(includeDeprecated: false) {
1366
                name
1367
              }
1368
              omittedValues: enumValues {
1369
                name
1370
              }
1371
            }
1372
          }
1373
        ';
1374
        $expected = [
1375
            'data' => [
1376
                '__type' => [
1377
                    'name'          => 'TestEnum',
1378
                    'trueValues'    => [
1379
                        ['name' => 'NONDEPRECATED'],
1380
                        ['name' => 'DEPRECATED'],
1381
                        ['name' => 'ALSONONDEPRECATED'],
1382
                    ],
1383
                    'falseValues'   => [
1384
                        ['name' => 'NONDEPRECATED'],
1385
                        ['name' => 'ALSONONDEPRECATED'],
1386
                    ],
1387
                    'omittedValues' => [
1388
                        ['name' => 'NONDEPRECATED'],
1389
                        ['name' => 'ALSONONDEPRECATED'],
1390
                    ],
1391
                ],
1392
            ],
1393
        ];
1394
        self::assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1395
    }
1396
1397
    /**
1398
     * @see it('fails as expected on the __type root field without an arg')
1399
     */
1400
    public function testFailsAsExpectedOnTheTypeRootFieldWithoutAnArg() : void
1401
    {
1402
        $TestType = new ObjectType([
1403
            'name'   => 'TestType',
1404
            'fields' => [
1405
                'testField' => [
1406
                    'type' => Type::string(),
1407
                ],
1408
            ],
1409
        ]);
1410
1411
        $schema   = new Schema(['query' => $TestType]);
1412
        $request  = '
1413
      {
1414
        __type {
1415
          name
1416
        }
1417
      }
1418
    ';
1419
        $expected = [
1420
            'errors' => [
1421
                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

1421
                /** @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...
1422
                    ProvidedRequiredArguments::missingFieldArgMessage('__type', 'name', 'String!'),
1423
                    [new SourceLocation(3, 9)]
1424
                ),
1425
            ],
1426
        ];
1427
        self::assertArraySubset($expected, GraphQL::executeQuery($schema, $request)->toArray());
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertArraySubset() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3494 ( Ignorable by Annotation )

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

1427
        /** @scrutinizer ignore-deprecated */ self::assertArraySubset($expected, GraphQL::executeQuery($schema, $request)->toArray());

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...
1428
    }
1429
1430
    /**
1431
     * @see it('exposes descriptions on types and fields')
1432
     */
1433
    public function testExposesDescriptionsOnTypesAndFields() : void
1434
    {
1435
        $QueryRoot = new ObjectType([
1436
            'name'   => 'QueryRoot',
1437
            'fields' => ['a' => Type::string()],
1438
        ]);
1439
1440
        $schema   = new Schema(['query' => $QueryRoot]);
1441
        $request  = '
1442
      {
1443
        schemaType: __type(name: "__Schema") {
1444
          name,
1445
          description,
1446
          fields {
1447
            name,
1448
            description
1449
          }
1450
        }
1451
      }
1452
        ';
1453
        $expected = [
1454
            'data' => [
1455
                'schemaType' => [
1456
                    'name'        => '__Schema',
1457
                    'description' => 'A GraphQL Schema defines the capabilities of a ' .
1458
                        'GraphQL server. It exposes all available types and ' .
1459
                        'directives on the server, as well as the entry ' .
1460
                        'points for query, mutation, and subscription operations.',
1461
                    'fields'      => [
1462
                        [
1463
                            'name'        => 'types',
1464
                            'description' => 'A list of all types supported by this server.',
1465
                        ],
1466
                        [
1467
                            'name'        => 'queryType',
1468
                            'description' => 'The type that query operations will be rooted at.',
1469
                        ],
1470
                        [
1471
                            'name'        => 'mutationType',
1472
                            'description' => 'If this server supports mutation, the type that ' .
1473
                                'mutation operations will be rooted at.',
1474
                        ],
1475
                        [
1476
                            'name'        => 'subscriptionType',
1477
                            'description' => 'If this server support subscription, the type that subscription operations will be rooted at.',
1478
                        ],
1479
                        [
1480
                            'name'        => 'directives',
1481
                            'description' => 'A list of all directives supported by this server.',
1482
                        ],
1483
                    ],
1484
                ],
1485
            ],
1486
        ];
1487
        self::assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1488
    }
1489
1490
    /**
1491
     * @see it('exposes descriptions on enums')
1492
     */
1493
    public function testExposesDescriptionsOnEnums() : void
1494
    {
1495
        $QueryRoot = new ObjectType([
1496
            'name'   => 'QueryRoot',
1497
            'fields' => ['a' => Type::string()],
1498
        ]);
1499
1500
        $schema   = new Schema(['query' => $QueryRoot]);
1501
        $request  = '
1502
      {
1503
        typeKindType: __type(name: "__TypeKind") {
1504
          name,
1505
          description,
1506
          enumValues {
1507
            name,
1508
            description
1509
          }
1510
        }
1511
      }
1512
    ';
1513
        $expected = [
1514
            'data' => [
1515
                'typeKindType' => [
1516
                    'name'        => '__TypeKind',
1517
                    'description' => 'An enum describing what kind of type a given `__Type` is.',
1518
                    'enumValues'  => [
1519
                        [
1520
                            'description' => 'Indicates this type is a scalar.',
1521
                            'name'        => 'SCALAR',
1522
                        ],
1523
                        [
1524
                            'description' => 'Indicates this type is an object. ' .
1525
                                '`fields` and `interfaces` are valid fields.',
1526
                            'name'        => 'OBJECT',
1527
                        ],
1528
                        [
1529
                            'description' => 'Indicates this type is an interface. ' .
1530
                                '`fields` and `possibleTypes` are valid fields.',
1531
                            'name'        => 'INTERFACE',
1532
                        ],
1533
                        [
1534
                            'description' => 'Indicates this type is a union. ' .
1535
                                '`possibleTypes` is a valid field.',
1536
                            'name'        => 'UNION',
1537
                        ],
1538
                        [
1539
                            'description' => 'Indicates this type is an enum. ' .
1540
                                '`enumValues` is a valid field.',
1541
                            'name'        => 'ENUM',
1542
                        ],
1543
                        [
1544
                            'description' => 'Indicates this type is an input object. ' .
1545
                                '`inputFields` is a valid field.',
1546
                            'name'        => 'INPUT_OBJECT',
1547
                        ],
1548
                        [
1549
                            'description' => 'Indicates this type is a list. ' .
1550
                                '`ofType` is a valid field.',
1551
                            'name'        => 'LIST',
1552
                        ],
1553
                        [
1554
                            'description' => 'Indicates this type is a non-null. ' .
1555
                                '`ofType` is a valid field.',
1556
                            'name'        => 'NON_NULL',
1557
                        ],
1558
                    ],
1559
                ],
1560
            ],
1561
        ];
1562
1563
        self::assertEquals($expected, GraphQL::executeQuery($schema, $request)->toArray());
1564
    }
1565
1566
    /**
1567
     * @see it('executes an introspection query without calling global fieldResolver')
1568
     */
1569
    public function testExecutesAnIntrospectionQueryWithoutCallingGlobalFieldResolver()
1570
    {
1571
        $QueryRoot = new ObjectType([
1572
            'name' => 'QueryRoot',
1573
            'fields' => [
1574
                'onlyField' => [ 'type' => Type::string() ],
1575
            ],
1576
        ]);
1577
1578
        $schema = new Schema([ 'query' => $QueryRoot ]);
1579
        $source = Introspection::getIntrospectionQuery();
1580
1581
        $calledForFields = [];
1582
        /* istanbul ignore next */
1583
        $fieldResolver = static function ($value, $_1, $_2, $info) use (&$calledForFields) {
1584
            $calledForFields[sprintf('%s::%s', $info->parentType->name, $info->fieldName)] = true;
1585
1586
            return $value;
1587
        };
1588
1589
        GraphQL::executeQuery($schema, $source, null, null, null, null, $fieldResolver);
1590
        self::assertEmpty($calledForFields);
1591
    }
1592
}
1593