pedantic: op_def

This commit is contained in:
Tobe O 2019-08-07 23:10:37 -04:00
parent a79f6c51c1
commit d15337714e

View file

@ -1,37 +1,58 @@
import 'package:source_span/source_span.dart'; import 'package:source_span/source_span.dart';
import '../token.dart'; import '../token.dart';
import 'definition.dart'; import 'definition.dart';
import 'directive.dart'; import 'directive.dart';
import 'selection_set.dart'; import 'selection_set.dart';
import 'variable_definitions.dart'; import 'variable_definitions.dart';
/// An executable GraphQL operation definition.
class OperationDefinitionContext extends ExecutableDefinitionContext { class OperationDefinitionContext extends ExecutableDefinitionContext {
final Token TYPE, NAME; /// The source tokens.
final Token typeToken, nameToken;
/// The variables defined in the operation.
final VariableDefinitionsContext variableDefinitions; final VariableDefinitionsContext variableDefinitions;
/// Any directives affixed to this operation.
final List<DirectiveContext> directives = []; final List<DirectiveContext> directives = [];
/// The selections to be applied to an object resolved in this operation.
final SelectionSetContext selectionSet; final SelectionSetContext selectionSet;
bool get isMutation => TYPE?.text == 'mutation'; /// Whether this operation is a `mutation`.
bool get isMutation => typeToken?.text == 'mutation';
bool get isSubscription => TYPE?.text == 'subscription'; /// Whether this operation is a `subscription`.
bool get isSubscription => typeToken?.text == 'subscription';
bool get isQuery => TYPE?.text == 'query' || TYPE == null; /// Whether this operation is a `query`.
bool get isQuery => typeToken?.text == 'query' || typeToken == null;
String get name => NAME?.text; /// The [String] value of the [nameToken].
String get name => nameToken?.text;
OperationDefinitionContext( /// Use [nameToken] instead.
this.TYPE, this.NAME, this.variableDefinitions, this.selectionSet) { @deprecated
assert(TYPE == null || Token get NAME => nameToken;
TYPE.text == 'query' ||
TYPE.text == 'mutation' || /// Use [typeToken] instead.
TYPE.text == 'subscription'); @deprecated
Token get TYPE => typeToken;
OperationDefinitionContext(this.typeToken, this.nameToken,
this.variableDefinitions, this.selectionSet) {
assert(typeToken == null ||
typeToken.text == 'query' ||
typeToken.text == 'mutation' ||
typeToken.text == 'subscription');
} }
@override @override
FileSpan get span { FileSpan get span {
if (TYPE == null) return selectionSet.span; if (typeToken == null) return selectionSet.span;
var out = NAME == null ? TYPE.span : TYPE.span.expand(NAME.span); var out = nameToken == null
? typeToken.span
: typeToken.span.expand(nameToken.span);
out = directives.fold<FileSpan>(out, (o, d) => o.expand(d.span)); out = directives.fold<FileSpan>(out, (o, d) => o.expand(d.span));
return out.expand(selectionSet.span); return out.expand(selectionSet.span);
} }