getOperationDefinition function

OperationDefinitionNode getOperationDefinition(
  1. DocumentNode document,
  2. String? operationName
)

Returns the AST Node for the GraphQL Operation.

Implementation

OperationDefinitionNode getOperationDefinition(
  DocumentNode document,
  String? operationName,
) {
  if (operationName != null) {
    return document.definitions
        .whereType<OperationDefinitionNode>()
        .firstWhere((definition) => definition.name?.value == operationName);
  } else {
    return document.definitions.whereType<OperationDefinitionNode>().first;
  }
}