1234567891011121314151617181920212223242526272829303132 |
- import type { DocumentNode, OperationDefinitionNode } from '../language/ast';
- import { Kind } from '../language/kinds';
- export function getOperationAST(
- documentAST: DocumentNode,
- operationName?: ?string,
- ): ?OperationDefinitionNode {
- let operation = null;
- for (const definition of documentAST.definitions) {
- if (definition.kind === Kind.OPERATION_DEFINITION) {
- if (operationName == null) {
-
-
-
- if (operation) {
- return null;
- }
- operation = definition;
- } else if (definition.name?.value === operationName) {
- return definition;
- }
- }
- }
- return operation;
- }
|