|
3 | 3 | namespace GraphQL\Tests\Language;
|
4 | 4 |
|
5 | 5 | use GraphQL\Language\AST\DocumentNode;
|
| 6 | +use GraphQL\Language\AST\FieldDefinitionNode; |
6 | 7 | use GraphQL\Language\AST\FieldNode;
|
| 8 | +use GraphQL\Language\AST\InputObjectTypeDefinitionNode; |
| 9 | +use GraphQL\Language\AST\InputValueDefinitionNode; |
7 | 10 | use GraphQL\Language\AST\NameNode;
|
8 | 11 | use GraphQL\Language\AST\Node;
|
9 | 12 | use GraphQL\Language\AST\NodeKind;
|
10 | 13 | use GraphQL\Language\AST\NodeList;
|
| 14 | +use GraphQL\Language\AST\ObjectTypeDefinitionNode; |
11 | 15 | use GraphQL\Language\AST\OperationDefinitionNode;
|
12 | 16 | use GraphQL\Language\AST\SelectionNode;
|
13 | 17 | use GraphQL\Language\AST\SelectionSetNode;
|
@@ -1684,4 +1688,48 @@ public function testMaintainsTypeInfoDuringEdit(): void
|
1684 | 1688 | $visited
|
1685 | 1689 | );
|
1686 | 1690 | }
|
| 1691 | + |
| 1692 | + public function testAncestorsForInputValueDefinition(): void |
| 1693 | + { |
| 1694 | + $ast = Parser::parse(' |
| 1695 | + input UserInput { |
| 1696 | + alwaysTwoItems: [Int] |
| 1697 | + } |
| 1698 | + '); |
| 1699 | + |
| 1700 | + Visitor::visit($ast, [ |
| 1701 | + NodeKind::LIST_TYPE => [ |
| 1702 | + 'enter' => function (Node $node, $key, $parent, $path, $ancestors): void { |
| 1703 | + self::assertInstanceOf(InputValueDefinitionNode::class, $parent); |
| 1704 | + self::assertCount(4, $ancestors); |
| 1705 | + self::assertInstanceOf(DocumentNode::class, $ancestors[0]); |
| 1706 | + self::assertInstanceOf(NodeList::class, $ancestors[1]); |
| 1707 | + self::assertInstanceOf(InputObjectTypeDefinitionNode::class, $ancestors[2]); |
| 1708 | + self::assertInstanceOf(NodeList::class, $ancestors[3]); |
| 1709 | + }, |
| 1710 | + ], |
| 1711 | + ]); |
| 1712 | + } |
| 1713 | + |
| 1714 | + public function testAncestorsForObjectTypeDefinition(): void |
| 1715 | + { |
| 1716 | + $ast = Parser::parse(' |
| 1717 | + type User { |
| 1718 | + alwaysTwoItems: [Int] |
| 1719 | + } |
| 1720 | + '); |
| 1721 | + |
| 1722 | + Visitor::visit($ast, [ |
| 1723 | + NodeKind::LIST_TYPE => [ |
| 1724 | + 'enter' => function (Node $node, $key, $parent, $path, $ancestors): void { |
| 1725 | + self::assertInstanceOf(FieldDefinitionNode::class, $parent); |
| 1726 | + self::assertCount(4, $ancestors); |
| 1727 | + self::assertInstanceOf(DocumentNode::class, $ancestors[0]); |
| 1728 | + self::assertInstanceOf(NodeList::class, $ancestors[1]); |
| 1729 | + self::assertInstanceOf(ObjectTypeDefinitionNode::class, $ancestors[2]); |
| 1730 | + self::assertInstanceOf(NodeList::class, $ancestors[3]); |
| 1731 | + }, |
| 1732 | + ], |
| 1733 | + ]); |
| 1734 | + } |
1687 | 1735 | }
|
0 commit comments