fromNode static method
Selection
fromNode(
- SelectionNode astNode, [
- TypeDefinition? schemaType,
- GetExecutableType? getType
Implementation
static Selection fromNode(
SelectionNode astNode, [
/// The [schemaType] of the containing element
TypeDefinition? schemaType,
GetExecutableType? getType,
]) {
if (astNode is FieldNode) {
// fields can only be selected on Interface and Object types
final fieldType = (schemaType != null)
? (schemaType as TypeDefinitionWithFieldSet)
.getField(astNode.name.value)
: null;
return Field(astNode, fieldType, getType);
}
if (astNode is FragmentSpreadNode) {
// Fragments can be specified on object types, interfaces, and unions.
// TODO need another mechanism for saturating fragment spreads.
// Probably adding a fragmentSpread argument to the getType when within the executable context.
return FragmentSpread(astNode, schemaType, getType);
}
if (astNode is InlineFragmentNode) {
// inline fragments must always specify a type condition
final onType = getType!.fromSchema!(astNode.typeCondition!.on.name.value);
return InlineFragment(astNode, onType, getType);
}
throw ArgumentError("$astNode is unsupported");
}