visitInParallel() static public method

static public visitInParallel ( $visitors ) : array
$visitors
return array
 /**
  * This uses a specialized visitor which runs multiple visitors in parallel,
  * while maintaining the visitor skip and break API.
  *
  * @param Schema $schema
  * @param TypeInfo $typeInfo
  * @param DocumentNode $documentNode
  * @param array $rules
  * @return array
  */
 public static function visitUsingRules(Schema $schema, TypeInfo $typeInfo, DocumentNode $documentNode, array $rules)
 {
     $context = new ValidationContext($schema, $documentNode, $typeInfo);
     $visitors = [];
     foreach ($rules as $rule) {
         $visitors[] = $rule($context);
     }
     Visitor::visit($documentNode, Visitor::visitWithTypeInfo($typeInfo, Visitor::visitInParallel($visitors)));
     return $context->getErrors();
 }
Example #2
0
 /**
  * @it allows for editing on leave
  */
 public function testAllowsForEditingOnLeave2()
 {
     $visited = [];
     $ast = Parser::parse('{ a, b, c { a, b, c } }', ['noLocation' => true]);
     $editedAst = Visitor::visit($ast, Visitor::visitInParallel([['leave' => function ($node) use(&$visited) {
         if ($node->kind === 'Field' && isset($node->name->value) && $node->name->value === 'b') {
             return Visitor::removeNode();
         }
     }], ['enter' => function ($node) use(&$visited) {
         $visited[] = ['enter', $node->kind, isset($node->value) ? $node->value : null];
     }, 'leave' => function ($node) use(&$visited) {
         $visited[] = ['leave', $node->kind, isset($node->value) ? $node->value : null];
     }]]));
     $this->assertEquals(Parser::parse('{ a, b, c { a, b, c } }', ['noLocation' => true]), $ast);
     $this->assertEquals(Parser::parse('{ a,    c { a,    c } }', ['noLocation' => true]), $editedAst);
     $this->assertEquals([['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', 'Field', null], ['enter', 'Name', 'c'], ['leave', 'Name', 'c'], ['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', 'Field', null], ['enter', 'Name', 'c'], ['leave', 'Name', 'c'], ['leave', 'Field', null], ['leave', 'SelectionSet', null], ['leave', 'Field', null], ['leave', 'SelectionSet', null], ['leave', 'OperationDefinition', null], ['leave', 'Document', null]], $visited);
 }