GraphQL\Language\Visitor::stop PHP Method

stop() public static method

Break visitor
public static stop ( ) : VisitorOperation
return VisitorOperation
    public static function stop()
    {
        $r = new VisitorOperation();
        $r->doBreak = true;
        return $r;
    }

Usage Example

Esempio n. 1
0
 public function testAllowsEarlyExitWhileVisiting()
 {
     $visited = [];
     $ast = Parser::parse('{ a, b { x }, c }');
     Visitor::visit($ast, ['enter' => function (Node $node) use(&$visited) {
         $visited[] = ['enter', $node->kind, isset($node->value) ? $node->value : null];
         if ($node instanceof Name && $node->value === 'x') {
             return Visitor::stop();
         }
     }, 'leave' => function (Node $node) use(&$visited) {
         $visited[] = ['leave', $node->kind, isset($node->value) ? $node->value : null];
     }]);
     $expected = [['enter', 'Document', null], ['enter', 'OperationDefinition', null], ['enter', 'SelectionSet', null], ['enter', 'Field', null], ['enter', 'Name', 'a'], ['leave', 'Name', 'a'], ['leave', 'Field', null], ['enter', 'Field', null], ['enter', 'Name', 'b'], ['leave', 'Name', 'b'], ['enter', 'SelectionSet', null], ['enter', 'Field', null], ['enter', 'Name', 'x']];
     $this->assertEquals($expected, $visited);
 }
All Usage Examples Of GraphQL\Language\Visitor::stop