operation static method

OperationDefinitionNode operation(
  1. OperationType type,
  2. String name, {
  3. List<VariableDefinitionNode>? variables,
  4. List<SelectionNode>? selections,
})

Creates an OperationDefinitionNode with simplified syntax.

This helper reduces the verbosity of operation definition creation.

Example:

operation(
  OperationType.query,
  'simple_query',
  selections: [field('pokemon', selections: [field('number')])],
)

Implementation

static OperationDefinitionNode operation(
  OperationType type,
  String name, {
  List<VariableDefinitionNode>? variables,
  List<SelectionNode>? selections,
}) {
  return OperationDefinitionNode(
    type: type,
    name: nameNode(name),
    variableDefinitions: variables ?? [],
    selectionSet: SelectionSetNode(selections: selections ?? []),
  );
}