field static method
FieldNode
field(})
Creates a FieldNode with simplified syntax.
This helper reduces verbose FieldNode construction from 8-10 lines to a single method call with optional parameters.
Example:
// Simple field
field('number')
// Field with arguments
field('pokemon', args: {'name': 'Charmander'})
// Field with nested selections
field('pokemon', selections: [field('number'), field('types')])
Implementation
static FieldNode field(
String name, {
String? alias,
Map<String, dynamic>? args,
List<SelectionNode>? selections,
}) {
return FieldNode(
name: nameNode(name),
alias: alias != null ? nameNode(alias) : null,
arguments:
args?.entries.map((e) => argument(e.key, e.value)).toList() ?? [],
selectionSet: selections != null
? SelectionSetNode(selections: selections)
: null,
);
}