Version 4.7.6
This commit is contained in:
1 parent
8ba7d43898
commit
7b7404e741
1085 files changed
+30590
-7837
No files matched your search
+31
@@ -584,6 +584,8 @@ class AST
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getOperationAST instead.
|
||||
*
|
||||
* Returns operation type ("query", "mutation" or "subscription") given a document and operation name
|
||||
*
|
||||
* @param string $operationName
|
||||
@@ -608,4 +610,33 @@ class AST
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user