Automattic\WooCommerce\Vendor\GraphQL\Utils
AST::getOperationAST
Returns the operation within a document by name.
If a name is not provided, an operation is only returned if the document has exactly one.
Method of the class: AST{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = AST::getOperationAST( $document, ?string $operationName ): ?OperationDefinitionNode;
- $document(DocumentNode) (required)
- .
- ?string $operationName
- .
Default:null
AST::getOperationAST() AST::getOperationAST code WC 10.9.1
public static function getOperationAST(DocumentNode $document, ?string $operationName = null): ?OperationDefinitionNode
{
$operation = null;
foreach ($document->definitions->getIterator() as $node) {
if (! $node instanceof OperationDefinitionNode) {
continue;
}
if ($operationName === null) {
// We found a second operation, so we bail instead of returning an ambiguous result.
if ($operation !== null) {
return null;
}
$operation = $node;
} elseif ($node->name instanceof NameNode && $node->name->value === $operationName) {
return $node;
}
}
return $operation;
}