visitOperationDefinitionNode method
Visit OperationDefinitionNode
.
Implementation
@override
OperationDefinitionNode visitOperationDefinitionNode(
OperationDefinitionNode node,
) {
// Subscriptions can only have a single root type
// https://spec.graphql.org/June2018/#example-2353b
if (node.type == OperationType.subscription) {
return node;
}
final hasTypename = node.selectionSet.selections
.whereType<FieldNode>()
.any((node) => node.name.value == '__typename');
if (hasTypename) return node;
return OperationDefinitionNode(
type: node.type,
name: node.name,
variableDefinitions: node.variableDefinitions,
directives: node.directives,
selectionSet: SelectionSetNode(
selections: <SelectionNode>[
FieldNode(
name: NameNode(value: '__typename'),
),
...node.selectionSet.selections,
],
),
);
}