platform/graphql_parser/lib/src/language/ast/fragment_definition.dart

50 lines
1.3 KiB
Dart
Raw Normal View History

2017-01-22 23:15:53 +00:00
import '../token.dart';
import 'definition.dart';
import 'directive.dart';
2017-07-05 22:44:13 +00:00
import 'package:source_span/source_span.dart';
2017-01-22 23:15:53 +00:00
import 'selection_set.dart';
import 'type_condition.dart';
2019-08-08 02:43:10 +00:00
/// A GraphQL query fragment definition.
class FragmentDefinitionContext extends ExecutableDefinitionContext {
2019-08-08 02:43:10 +00:00
/// The source tokens.
final Token fragmentToken, nameToken, onToken;
/// The type to which this fragment applies.
2017-01-22 23:15:53 +00:00
final TypeConditionContext typeCondition;
2019-08-08 02:43:10 +00:00
/// Any directives on the fragment.
2017-01-22 23:15:53 +00:00
final List<DirectiveContext> directives = [];
2019-08-08 02:43:10 +00:00
/// The selections to apply when the [typeCondition] is met.
2017-01-22 23:15:53 +00:00
final SelectionSetContext selectionSet;
2019-08-08 02:43:10 +00:00
/// The [String] value of the [nameToken].
String get name => nameToken.text;
FragmentDefinitionContext(this.fragmentToken, this.nameToken, this.onToken,
this.typeCondition, this.selectionSet);
/// Use [fragmentToken] instead.
@deprecated
Token get FRAGMENT => fragmentToken;
/// Use [nameToken] instead.
@deprecated
Token get NAME => nameToken;
2017-01-22 23:15:53 +00:00
2019-08-08 02:43:10 +00:00
/// Use [onToken] instead.
@deprecated
Token get ON => onToken;
2017-01-22 23:15:53 +00:00
@override
2017-07-05 22:44:13 +00:00
FileSpan get span {
2019-08-08 02:43:10 +00:00
var out = fragmentToken.span
.expand(nameToken.span)
.expand(onToken.span)
2017-07-05 22:44:13 +00:00
.expand(typeCondition.span);
out = directives.fold<FileSpan>(out, (o, d) => o.expand(d.span));
return out.expand(selectionSet.span);
}
2017-01-22 23:15:53 +00:00
}