Completed
Push — master ( 38e7e4...ad5676 )
by Alexandr
03:04
created

ParserTest::mutationProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 86
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 86
rs 8.6583
c 0
b 0
f 0
cc 1
eloc 49
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Date: 01.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\Tests\Parser;
9
10
use Youshido\GraphQL\Parser\Ast\Argument;
11
use Youshido\GraphQL\Parser\Ast\ArgumentValue\InputList;
12
use Youshido\GraphQL\Parser\Ast\ArgumentValue\InputObject;
13
use Youshido\GraphQL\Parser\Ast\ArgumentValue\Literal;
14
use Youshido\GraphQL\Parser\Ast\ArgumentValue\Variable;
15
use Youshido\GraphQL\Parser\Ast\ArgumentValue\VariableReference;
16
use Youshido\GraphQL\Parser\Ast\Field;
17
use Youshido\GraphQL\Parser\Ast\Fragment;
18
use Youshido\GraphQL\Parser\Ast\FragmentReference;
19
use Youshido\GraphQL\Parser\Ast\Mutation;
20
use Youshido\GraphQL\Parser\Ast\Query;
21
use Youshido\GraphQL\Parser\Ast\TypedFragmentReference;
22
use Youshido\GraphQL\Parser\Location;
23
use Youshido\GraphQL\Parser\Parser;
24
25
class ParserTest extends \PHPUnit_Framework_TestCase
26
{
27
28
    public function testEmptyParser()
29
    {
30
        $parser = new Parser();
31
32
        $this->assertEquals([
33
            'queries'            => [],
34
            'mutations'          => [],
35
            'fragments'          => [],
36
            'fragmentReferences' => [],
37
            'variables'          => [],
38
            'variableReferences' => [],
39
        ], $parser->parse());
40
    }
41
42
    /**
43
     * @expectedException Youshido\GraphQL\Exception\Parser\SyntaxErrorException
44
     */
45
    public function testInvalidSelection()
46
    {
47
        $parser = new Parser();
48
        $data   = $parser->parse('
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
        {
50
            test {
51
                id
52
                image {
53
                    
54
                }
55
            }
56
        }
57
        ');
58
    }
59
60
    public function testComments()
61
    {
62
        $query = <<<GRAPHQL
63
# asdasd "asdasdasd"
64
# comment line 2
65
66
query {
67
    authors (category: "#2") { #asda asd
68
        _id
69
    }
70
}
71
GRAPHQL;
72
73
        $parser     = new Parser();
74
        $parsedData = $parser->parse($query);
75
76
        $this->assertEquals($parsedData, [
77
            'queries'            => [
78
                new Query('authors', null,
79
                    [
80
                        new Argument('category', new Literal('#2', new Location(5, 25)), new Location(5, 14))
81
                    ],
82
                    [
83
                        new Field('_id', null, [], new Location(6, 9)),
84
                    ], new Location(5, 5))
85
            ],
86
            'mutations'          => [],
87
            'fragments'          => [],
88
            'fragmentReferences' => [],
89
            'variables'          => [],
90
            'variableReferences' => []
91
        ]);
92
    }
93
94
95
    /**
96
     * @param $query string
97
     *
98
     * @dataProvider wrongQueriesProvider
99
     * @expectedException Youshido\GraphQL\Exception\Parser\SyntaxErrorException
100
     */
101
    public function testWrongQueries($query)
102
    {
103
        $parser = new Parser();
104
105
        $parser->parse($query);
106
    }
107
108
    public function testCommas()
109
    {
110
        $parser = new Parser();
111
        $data   = $parser->parse('{ foo,       ,,  , bar  }');
112
        $this->assertEquals([
113
            new Query('foo', '', [], [], new Location(1, 3)),
114
            new Query('bar', '', [], [], new Location(1, 20)),
115
        ], $data['queries']);
116
    }
117
118
    public function testQueryWithNoFields()
119
    {
120
        $parser = new Parser();
121
        $data   = $parser->parse('{ name }');
122
        $this->assertEquals([
123
            'queries'            => [
124
                new Query('name', '', [], [], new Location(1, 3))
125
            ],
126
            'mutations'          => [],
127
            'fragments'          => [],
128
            'fragmentReferences' => [],
129
            'variables'          => [],
130
            'variableReferences' => [],
131
        ], $data);
132
    }
133
134
    public function testQueryWithFields()
135
    {
136
        $parser = new Parser();
137
        $data   = $parser->parse('{ post, user { name } }');
138
        $this->assertEquals([
139
            'queries'            => [
140
                new Query('post', null, [], [], new Location(1, 3)),
141
                new Query('user', null, [], [
142
                    new Field('name', null, [], new Location(1, 16))
143
                ], new Location(1, 9))
144
            ],
145
            'mutations'          => [],
146
            'fragments'          => [],
147
            'fragmentReferences' => [],
148
            'variables'          => [],
149
            'variableReferences' => [],
150
        ], $data);
151
    }
152
153 View Code Duplication
    public function testFragmentWithFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
154
    {
155
        $parser = new Parser();
156
        $data   = $parser->parse('
157
            fragment FullType on __Type {
158
                kind
159
                fields {
160
                    name
161
                }
162
            }');
163
        $this->assertEquals([
164
            'queries'            => [],
165
            'mutations'          => [],
166
            'fragments'          => [
167
                new Fragment('FullType', '__Type', [
168
                    new Field('kind', null, [], new Location(3, 17)),
169
                    new Query('fields', null, [], [
170
                        new Field('name', null, [], new Location(5, 21))
171
                    ], new Location(4, 17))
172
                ], new Location(2, 22))
173
            ],
174
            'fragmentReferences' => [],
175
            'variables'          => [],
176
            'variableReferences' => [],
177
        ], $data);
178
    }
179
180
    public function testInspectionQuery()
181
    {
182
        $parser = new Parser();
183
184
        $data = $parser->parse('
185
            query IntrospectionQuery {
186
                __schema {
187
                    queryType { name }
188
                    mutationType { name }
189
                    types {
190
                        ...FullType
191
                    }
192
                    directives {
193
                        name
194
                        description
195
                        args {
196
                            ...InputValue
197
                        }
198
                        onOperation
199
                        onFragment
200
                        onField
201
                    }
202
                }
203
            }
204
205
            fragment FullType on __Type {
206
                kind
207
                name
208
                description
209
                fields {
210
                    name
211
                    description
212
                    args {
213
                        ...InputValue
214
                    }
215
                    type {
216
                        ...TypeRef
217
                    }
218
                    isDeprecated
219
                    deprecationReason
220
                }
221
                inputFields {
222
                    ...InputValue
223
                }
224
                interfaces {
225
                    ...TypeRef
226
                }
227
                enumValues {
228
                    name
229
                    description
230
                    isDeprecated
231
                    deprecationReason
232
                }
233
                possibleTypes {
234
                    ...TypeRef
235
                }
236
            }
237
238
            fragment InputValue on __InputValue {
239
                name
240
                description
241
                type { ...TypeRef }
242
                defaultValue
243
            }
244
245
            fragment TypeRef on __Type {
246
                kind
247
                name
248
                ofType {
249
                    kind
250
                    name
251
                    ofType {
252
                        kind
253
                        name
254
                        ofType {
255
                            kind
256
                            name
257
                        }
258
                    }
259
                }
260
            }
261
        ');
262
263
        $this->assertEquals([
264
            'queries'            => [
265
                new Query('__schema', null, [], [
266
                    new Query('queryType', null, [], [
267
                        new Field('name', null, [], new Location(4, 33))
268
                    ], new Location(4, 21)),
269
                    new Query('mutationType', null, [], [
270
                        new Field('name', null, [], new Location(5, 36))
271
                    ], new Location(5, 21)),
272
                    new Query('types', null, [], [
273
                        new FragmentReference('FullType', new Location(7, 28))
274
                    ], new Location(6, 21)),
275
                    new Query('directives', null, [], [
276
                        new Field('name', null, [], new Location(10, 25)),
277
                        new Field('description', null, [], new Location(11, 25)),
278
                        new Query('args', null, [], [
279
                            new FragmentReference('InputValue', new Location(13, 32)),
280
                        ], new Location(12, 25)),
281
                        new Field('onOperation', null, [], new Location(15, 25)),
282
                        new Field('onFragment', null, [], new Location(16, 25)),
283
                        new Field('onField', null, [], new Location(17, 25)),
284
                    ], new Location(9, 21)),
285
                ], new Location(3, 17))
286
            ],
287
            'mutations'          => [],
288
            'fragments'          => [
289
                new Fragment('FullType', '__Type', [
290
                    new Field('kind', null, [], new Location(23, 17)),
291
                    new Field('name', null, [], new Location(24, 17)),
292
                    new Field('description', null, [], new Location(25, 17)),
293
                    new Query('fields', null, [], [
294
                        new Field('name', null, [], new Location(27, 21)),
295
                        new Field('description', null, [], new Location(28, 21)),
296
                        new Query('args', null, [], [
297
                            new FragmentReference('InputValue', new Location(30, 28)),
298
                        ], new Location(29, 21)),
299
                        new Query('type', null, [], [
300
                            new FragmentReference('TypeRef', new Location(33, 28)),
301
                        ], new Location(32, 21)),
302
                        new Field('isDeprecated', null, [], new Location(35, 21)),
303
                        new Field('deprecationReason', null, [], new Location(36, 21)),
304
                    ], new Location(26, 17)),
305
                    new Query('inputFields', null, [], [
306
                        new FragmentReference('InputValue', new Location(39, 24)),
307
                    ], new Location(38, 17)),
308
                    new Query('interfaces', null, [], [
309
                        new FragmentReference('TypeRef', new Location(42, 24)),
310
                    ], new Location(41, 17)),
311
                    new Query('enumValues', null, [], [
312
                        new Field('name', null, [], new Location(45, 21)),
313
                        new Field('description', null, [], new Location(46, 21)),
314
315
                        new Field('isDeprecated', null, [], new Location(47, 21)),
316
                        new Field('deprecationReason', null, [], new Location(48, 21)),
317
                    ], new Location(44, 17)),
318
                    new Query('possibleTypes', null, [], [
319
                        new FragmentReference('TypeRef', new Location(51, 24)),
320
                    ], new Location(50, 17)),
321
                ], new Location(22, 22)),
322
                new Fragment('InputValue', '__InputValue', [
323
                    new Field('name', null, [], new Location(56, 17)),
324
                    new Field('description', null, [], new Location(57, 17)),
325
                    new Query('type', null, [], [
326
                        new FragmentReference('TypeRef', new Location(58, 27)),
327
                    ], new Location(58, 17)),
328
                    new Field('defaultValue', null, [], new Location(59, 17)),
329
                ], new Location(55, 22)),
330
                new Fragment('TypeRef', '__Type', [
331
                    new Field('kind', null, [], new Location(63, 17)),
332
                    new Field('name', null, [], new Location(64, 17)),
333
                    new Query('ofType', null, [], [
334
                        new Field('kind', null, [], new Location(66, 21)),
335
                        new Field('name', null, [], new Location(67, 21)),
336
                        new Query('ofType', null, [], [
337
                            new Field('kind', null, [], new Location(69, 25)),
338
                            new Field('name', null, [], new Location(70, 25)),
339
                            new Query('ofType', null, [], [
340
                                new Field('kind', null, [], new Location(72, 29)),
341
                                new Field('name', null, [], new Location(73, 29)),
342
                            ], new Location(71, 25)),
343
                        ], new Location(68, 21)),
344
                    ], new Location(65, 17)),
345
                ], new Location(62, 22)),
346
            ],
347
            'fragmentReferences' => [
348
                new FragmentReference('FullType', new Location(7, 28)),
349
                new FragmentReference('InputValue', new Location(13, 32)),
350
                new FragmentReference('InputValue', new Location(30, 28)),
351
                new FragmentReference('TypeRef', new Location(33, 28)),
352
                new FragmentReference('InputValue', new Location(39, 24)),
353
                new FragmentReference('TypeRef', new Location(42, 24)),
354
                new FragmentReference('TypeRef', new Location(51, 24)),
355
                new FragmentReference('TypeRef', new Location(58, 27)),
356
            ],
357
            'variables'          => [],
358
            'variableReferences' => []
359
        ], $data);
360
    }
361
362
    public function wrongQueriesProvider()
363
    {
364
        return [
365
            ['{ test (a: "asd", b: <basd>) { id }'],
366
            ['{ test (asd: [..., asd]) { id } }'],
367
            ['{ test (asd: { "a": 4, "m": null, "asd": false  "b": 5, "c" : { a }}) { id } }'],
368
            ['asdasd'],
369
            ['mutation { test(asd: ... ){ ...,asd, asd } }'],
370
            ['mutation { test{ . test on Test { id } } }'],
371
            ['mutation { test( a: "asdd'],
372
            ['mutation { test( a: { "asd": 12 12'],
373
            ['mutation { test( a: { "asd": 12'],
374
        ];
375
    }
376
377
    /**
378
     * @dataProvider mutationProvider
379
     */
380
    public function testMutations($query, $structure)
381
    {
382
        $parser = new Parser();
383
384
        $parsedStructure = $parser->parse($query);
385
386
        $this->assertEquals($parsedStructure, $structure);
387
    }
388
389 View Code Duplication
    public function testTypedFragment()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
390
    {
391
        $parser          = new Parser();
392
        $parsedStructure = $parser->parse('
393
            {
394
                test: test {
395
                    name,
396
                    ... on UnionType {
397
                        unionName
398
                    }
399
                }
400
            }
401
        ');
402
403
        $this->assertEquals($parsedStructure, [
404
            'queries'            => [
405
                new Query('test', 'test', [],
406
                    [
407
                        new Field('name', null, [], new Location(4, 21)),
408
                        new TypedFragmentReference('UnionType', [new Field('unionName', null, [], new Location(6, 25))], new Location(5, 28))
409
                    ], new Location(3, 23))
410
            ],
411
            'mutations'          => [],
412
            'fragments'          => [],
413
            'fragmentReferences' => [],
414
            'variables'          => [],
415
            'variableReferences' => []
416
        ]);
417
    }
418
419
    public function mutationProvider()
420
    {
421
        return [
422
            [
423
                'query ($variable: Int){ query ( teas: $variable ) { alias: name } }',
424
                [
425
                    'queries'            => [
426
                        new Query('query', null,
427
                            [
428
                                new Argument('teas', new VariableReference('variable', (new Variable('variable', 'Int', false, false, new Location(1, 8)))->setUsed(true), new Location(1, 39)), new Location(1, 33))
429
                            ],
430
                            [
431
                                new Field('name', 'alias', [], new Location(1, 60))
432
                            ], new Location(1, 25))
433
                    ],
434
                    'mutations'          => [],
435
                    'fragments'          => [],
436
                    'fragmentReferences' => [],
437
                    'variables'          => [
438
                        (new Variable('variable', 'Int', false, false, new Location(1, 8)))->setUsed(true)
439
                    ],
440
                    'variableReferences' => [
441
                        new VariableReference('variable', (new Variable('variable', 'Int', false, false, new Location(1, 8)))->setUsed(true), new Location(1, 39))
442
                    ]
443
                ]
444
            ],
445
            [
446
                '{ query { alias: name } }',
447
                [
448
                    'queries'            => [
449
                        new Query('query', null, [], [new Field('name', 'alias', [], new Location(1, 18))], new Location(1, 3))
450
                    ],
451
                    'mutations'          => [],
452
                    'fragments'          => [],
453
                    'fragmentReferences' => [],
454
                    'variables'          => [],
455
                    'variableReferences' => []
456
                ]
457
            ],
458
            [
459
                'mutation { createUser ( email: "[email protected]", active: true ) { id } }',
460
                [
461
                    'queries'            => [],
462
                    'mutations'          => [
463
                        new Mutation(
464
                            'createUser',
465
                            null,
466
                            [
467
                                new Argument('email', new Literal('[email protected]', new Location(1, 33)), new Location(1, 25)),
468
                                new Argument('active', new Literal(true, new Location(1, 57)), new Location(1, 49)),
469
                            ],
470
                            [
471
                                new Field('id', null, [], new Location(1, 66))
472
                            ],
473
                            new Location(1, 12)
474
                        )
475
                    ],
476
                    'fragments'          => [],
477
                    'fragmentReferences' => [],
478
                    'variables'          => [],
479
                    'variableReferences' => []
480
                ]
481
            ],
482
            [
483
                'mutation { test : createUser (id: 4) }',
484
                [
485
                    'queries'            => [],
486
                    'mutations'          => [
487
                        new Mutation(
488
                            'createUser',
489
                            'test',
490
                            [
491
                                new Argument('id', new Literal(4, new Location(1, 35)), new Location(1, 31)),
492
                            ],
493
                            [],
494
                            new Location(1, 19)
495
                        )
496
                    ],
497
                    'fragments'          => [],
498
                    'fragmentReferences' => [],
499
                    'variables'          => [],
500
                    'variableReferences' => []
501
                ]
502
            ]
503
        ];
504
    }
505
506
    /**
507
     * @dataProvider queryProvider
508
     */
509
    public function testParser($query, $structure)
510
    {
511
        $parser          = new Parser();
512
        $parsedStructure = $parser->parse($query);
513
514
        $this->assertEquals($structure, $parsedStructure);
515
    }
516
517
518
    public function queryProvider()
519
    {
520
        return [
521
            [
522
                '{ film(id: 1 filmID: 2) { title } }',
523
                [
524
                    'queries'            => [
525
                        new Query('film', null, [
526
                            new Argument('id', new Literal(1, new Location(1, 12)), new Location(1, 8)),
527
                            new Argument('filmID', new Literal(2, new Location(1, 22)), new Location(1, 14))
528
                        ], [
529
                            new Field('title', null, [], new Location(1, 27)),
530
                        ], new Location(1, 3))
531
                    ],
532
                    'mutations'          => [],
533
                    'fragments'          => [],
534
                    'fragmentReferences' => [],
535
                    'variables'          => [],
536
                    'variableReferences' => []
537
                ]
538
            ],
539
            [
540
                '{ test (id: -5) { id } } ',
541
                [
542
                    'queries'            => [
543
                        new Query('test', null, [
544
                            new Argument('id', new Literal(-5, new Location(1, 13)), new Location(1, 9))
545
                        ], [
546
                            new Field('id', null, [], new Location(1, 19)),
547
                        ], new Location(1, 3))
548
                    ],
549
                    'mutations'          => [],
550
                    'fragments'          => [],
551
                    'fragmentReferences' => [],
552
                    'variables'          => [],
553
                    'variableReferences' => []
554
                ]
555
            ],
556
            [
557
                "{ test (id: -5) \r\n { id } } ",
558
                [
559
                    'queries'            => [
560
                        new Query('test', null, [
561
                            new Argument('id', new Literal(-5, new Location(1, 13)), new Location(1, 9))
562
                        ], [
563
                            new Field('id', null, [], new Location(2, 4)),
564
                        ], new Location(1, 3))
565
                    ],
566
                    'mutations'          => [],
567
                    'fragments'          => [],
568
                    'fragmentReferences' => [],
569
                    'variables'          => [],
570
                    'variableReferences' => []
571
                ]
572
            ],
573
            [
574
                'query CheckTypeOfLuke {
575
                  hero(episode: EMPIRE) {
576
                    __typename,
577
                    name
578
                  }
579
                }',
580
                [
581
                    'queries'            => [
582
                        new Query('hero', null, [
583
                            new Argument('episode', new Literal('EMPIRE', new Location(2, 33)), new Location(2, 24))
584
                        ], [
585
                            new Field('__typename', null, [], new Location(3, 21)),
586
                            new Field('name', null, [], new Location(4, 21)),
587
                        ], new Location(2, 19))
588
                    ],
589
                    'mutations'          => [],
590
                    'fragments'          => [],
591
                    'fragmentReferences' => [],
592
                    'variables'          => [],
593
                    'variableReferences' => []
594
                ]
595
            ],
596
            [
597
                '{ test { __typename, id } }',
598
                [
599
                    'queries'            => [
600
                        new Query('test', null, [], [
601
                            new Field('__typename', null, [], new Location(1, 10)),
602
                            new Field('id', null, [], new Location(1, 22)),
603
                        ], new Location(1, 3))
604
                    ],
605
                    'mutations'          => [],
606
                    'fragments'          => [],
607
                    'fragmentReferences' => [],
608
                    'variables'          => [],
609
                    'variableReferences' => []
610
                ]
611
            ],
612
            [
613
                '{}',
614
                [
615
                    'queries'            => [],
616
                    'mutations'          => [],
617
                    'fragments'          => [],
618
                    'fragmentReferences' => [],
619
                    'variables'          => [],
620
                    'variableReferences' => []
621
                ]
622
            ],
623
            [
624
                'query test {}',
625
                [
626
                    'queries'            => [],
627
                    'mutations'          => [],
628
                    'fragments'          => [],
629
                    'fragmentReferences' => [],
630
                    'variables'          => [],
631
                    'variableReferences' => []
632
                ]
633
            ],
634
            [
635
                'query {}',
636
                [
637
                    'queries'            => [],
638
                    'mutations'          => [],
639
                    'fragments'          => [],
640
                    'fragmentReferences' => [],
641
                    'variables'          => [],
642
                    'variableReferences' => []
643
                ]
644
            ],
645
            [
646
                'mutation setName { setUserName }',
647
                [
648
                    'queries'            => [],
649
                    'mutations'          => [new Mutation('setUserName', null, [], [], new Location(1, 20))],
650
                    'fragments'          => [],
651
                    'fragmentReferences' => [],
652
                    'variables'          => [],
653
                    'variableReferences' => []
654
                ]
655
            ],
656
            [
657
                '{ test { ...userDataFragment } } fragment userDataFragment on User { id, name, email }',
658
                [
659
                    'queries'            => [
660
                        new Query('test', null, [], [new FragmentReference('userDataFragment', new Location(1, 13))], new Location(1, 3))
661
                    ],
662
                    'mutations'          => [],
663
                    'fragments'          => [
664
                        new Fragment('userDataFragment', 'User', [
665
                            new Field('id', null, [], new Location(1, 70)),
666
                            new Field('name', null, [], new Location(1, 74)),
667
                            new Field('email', null, [], new Location(1, 80))
668
                        ], new Location(1, 43))
669
                    ],
670
                    'fragmentReferences' => [
671
                        new FragmentReference('userDataFragment', new Location(1, 13))
672
                    ],
673
                    'variables'          => [],
674
                    'variableReferences' => []
675
                ]
676
            ],
677
            [
678
                '{ user (id: 10, name: "max", float: 123.123 ) { id, name } }',
679
                [
680
                    'queries'            => [
681
                        new Query(
682
                            'user',
683
                            null,
684
                            [
685
                                new Argument('id', new Literal('10', new Location(1, 13)), new Location(1, 9)),
686
                                new Argument('name', new Literal('max', new Location(1, 24)), new Location(1, 17)),
687
                                new Argument('float', new Literal('123.123', new Location(1, 37)), new Location(1, 30))
688
                            ],
689
                            [
690
                                new Field('id', null, [], new Location(1, 49)),
691
                                new Field('name', null, [], new Location(1, 53))
692
                            ],
693
                            new Location(1, 3)
694
                        )
695
                    ],
696
                    'mutations'          => [],
697
                    'fragments'          => [],
698
                    'fragmentReferences' => [],
699
                    'variables'          => [],
700
                    'variableReferences' => []
701
                ]
702
            ],
703
            [
704
                '{ allUsers : users ( id: [ 1, 2, 3] ) { id } }',
705
                [
706
                    'queries'            => [
707
                        new Query(
708
                            'users',
709
                            'allUsers',
710
                            [
711
                                new Argument('id', new InputList([1, 2, 3], new Location(1, 26)), new Location(1, 22))
712
                            ],
713
                            [
714
                                new Field('id', null, [], new Location(1, 41))
715
                            ],
716
                            new Location(1, 14)
717
                        )
718
                    ],
719
                    'mutations'          => [],
720
                    'fragments'          => [],
721
                    'fragmentReferences' => [],
722
                    'variables'          => [],
723
                    'variableReferences' => []
724
                ]
725
            ],
726
            [
727
                '{ allUsers : users ( id: [ 1, "2", true, null] ) { id } }',
728
                [
729
                    'queries'            => [
730
                        new Query(
731
                            'users',
732
                            'allUsers',
733
                            [
734
                                new Argument('id', new InputList([1, "2", true, null], new Location(1, 26)), new Location(1, 22))
735
                            ],
736
                            [
737
                                new Field('id', null, [], new Location(1, 52))
738
                            ],
739
                            new Location(1, 14)
740
                        )
741
                    ],
742
                    'mutations'          => [],
743
                    'fragments'          => [],
744
                    'fragmentReferences' => [],
745
                    'variables'          => [],
746
                    'variableReferences' => []
747
                ]
748
            ],
749
            [
750
                '{ allUsers : users ( object: { "a": 123, "d": "asd",  "b" : [ 1, 2, 4 ], "c": { "a" : 123, "b":  "asd" } } ) { id } }',
751
                [
752
                    'queries'            => [
753
                        new Query(
754
                            'users',
755
                            'allUsers',
756
                            [
757
                                new Argument('object', new InputObject([
758
                                    'a' => 123,
759
                                    'd' => 'asd',
760
                                    'b' => [1, 2, 4],
761
                                    'c' => new InputObject([
762
                                        'a' => 123,
763
                                        'b' => 'asd'
764
                                    ], new Location(1, 79))
765
                                ], new Location(1, 30)), new Location(1, 22))
766
                            ],
767
                            [
768
                                new Field('id', null, [], new Location(1, 112))
769
                            ],
770
                            new Location(1, 14)
771
                        )
772
                    ],
773
                    'mutations'          => [],
774
                    'fragments'          => [],
775
                    'fragmentReferences' => [],
776
                    'variables'          => [],
777
                    'variableReferences' => []
778
                ]
779
            ]
780
        ];
781
    }
782
783
    public function testVariablesInQuery()
784
    {
785
        $parser = new Parser();
786
787
        $data = $parser->parse('
788
            query StarWarsAppHomeRoute($names_0:[String!]!, $query: String) {
789
              factions(names:$names_0, test: $query) {
790
                id,
791
                ...F2
792
              }
793
            }
794
            fragment F0 on Ship {
795
              id,
796
              name
797
            }
798
            fragment F1 on Faction {
799
              id,
800
              factionId
801
            }
802
            fragment F2 on Faction {
803
              id,
804
              factionId,
805
              name,
806
              _shipsDRnzJ:ships(first:10) {
807
                edges {
808
                  node {
809
                    id,
810
                    ...F0
811
                  },
812
                  cursor
813
                },
814
                pageInfo {
815
                  hasNextPage,
816
                  hasPreviousPage
817
                }
818
              },
819
              ...F1
820
            }
821
        ');
822
823
        $this->assertArrayNotHasKey('errors', $data);
824
    }
825
826
}
827