|
3 | 3 | namespace GraphQL\Tests\Type;
|
4 | 4 |
|
5 | 5 | use GraphQL\GraphQL;
|
| 6 | +use GraphQL\Type\Definition\ListOfType; |
6 | 7 | use GraphQL\Type\Definition\ObjectType;
|
7 | 8 | use GraphQL\Type\Definition\ResolveInfo;
|
8 | 9 | use GraphQL\Type\Definition\Type;
|
@@ -518,4 +519,81 @@ public function testPathAndUnaliasedPath(): void
|
518 | 519 | ],
|
519 | 520 | ], $result);
|
520 | 521 | }
|
| 522 | + |
| 523 | + public function testPathAndUnaliasedPathForList(): void |
| 524 | + { |
| 525 | + $level2 = new ObjectType([ |
| 526 | + 'name' => 'level2', |
| 527 | + 'fields' => [ |
| 528 | + 'scalar1' => [ |
| 529 | + 'type' => Type::string(), |
| 530 | + 'resolve' => static function ($value, array $args, $context, ResolveInfo $info) { |
| 531 | + return 'path: ' . implode('.', $info->path) . ', unaliasedPath: ' . implode('.', $info->unaliasedPath); |
| 532 | + }, |
| 533 | + ], |
| 534 | + 'scalar2' => [ |
| 535 | + 'type' => Type::string(), |
| 536 | + 'resolve' => static function ($value, array $args, $context, ResolveInfo $info) { |
| 537 | + return 'path: ' . implode('.', $info->path) . ', unaliasedPath: ' . implode('.', $info->unaliasedPath); |
| 538 | + }, |
| 539 | + ], |
| 540 | + ], |
| 541 | + ]); |
| 542 | + $level1 = new ObjectType([ |
| 543 | + 'name' => 'level1', |
| 544 | + 'fields' => [ |
| 545 | + 'level2' => [ |
| 546 | + 'type' => ListOfType::listOf($level2), |
| 547 | + 'resolve' => function () { |
| 548 | + return ['a', 'b', 'c']; |
| 549 | + }, |
| 550 | + ], |
| 551 | + ], |
| 552 | + ]); |
| 553 | + |
| 554 | + $query = new ObjectType([ |
| 555 | + 'name' => 'Query', |
| 556 | + 'fields' => [ |
| 557 | + 'level1' => [ |
| 558 | + 'type' => $level1, |
| 559 | + 'resolve' => function () { |
| 560 | + return true; |
| 561 | + }, |
| 562 | + ], |
| 563 | + ], |
| 564 | + ]); |
| 565 | + |
| 566 | + $result = GraphQL::executeQuery( |
| 567 | + new Schema(['query' => $query]), |
| 568 | + <<<GRAPHQL |
| 569 | + query { |
| 570 | + level1 { |
| 571 | + level2 { |
| 572 | + scalar1 |
| 573 | + } |
| 574 | + level1000: level2 { |
| 575 | + scalar2 |
| 576 | + } |
| 577 | + } |
| 578 | + } |
| 579 | + GRAPHQL |
| 580 | + )->toArray(); |
| 581 | + |
| 582 | + self::assertSame([ |
| 583 | + 'data' => [ |
| 584 | + 'level1' => [ |
| 585 | + 'level2' => [ |
| 586 | + ['scalar1' => 'path: level1.level2.0.scalar1, unaliasedPath: level1.level2.0.scalar1'], |
| 587 | + ['scalar1' => 'path: level1.level2.1.scalar1, unaliasedPath: level1.level2.1.scalar1'], |
| 588 | + ['scalar1' => 'path: level1.level2.2.scalar1, unaliasedPath: level1.level2.2.scalar1'], |
| 589 | + ], |
| 590 | + 'level1000' => [ |
| 591 | + ['scalar2' => 'path: level1.level1000.0.scalar2, unaliasedPath: level1.level2.0.scalar2'], |
| 592 | + ['scalar2' => 'path: level1.level1000.1.scalar2, unaliasedPath: level1.level2.1.scalar2'], |
| 593 | + ['scalar2' => 'path: level1.level1000.2.scalar2, unaliasedPath: level1.level2.2.scalar2'], |
| 594 | + ], |
| 595 | + ], |
| 596 | + ], |
| 597 | + ], $result); |
| 598 | + } |
521 | 599 | }
|
0 commit comments