pedantic: op_def
This commit is contained in:
parent
a79f6c51c1
commit
d15337714e
1 changed files with 35 additions and 14 deletions
|
@ -1,37 +1,58 @@
|
|||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../token.dart';
|
||||
import 'definition.dart';
|
||||
import 'directive.dart';
|
||||
import 'selection_set.dart';
|
||||
import 'variable_definitions.dart';
|
||||
|
||||
/// An executable GraphQL operation definition.
|
||||
class OperationDefinitionContext extends ExecutableDefinitionContext {
|
||||
final Token TYPE, NAME;
|
||||
/// The source tokens.
|
||||
final Token typeToken, nameToken;
|
||||
|
||||
/// The variables defined in the operation.
|
||||
final VariableDefinitionsContext variableDefinitions;
|
||||
|
||||
/// Any directives affixed to this operation.
|
||||
final List<DirectiveContext> directives = [];
|
||||
|
||||
/// The selections to be applied to an object resolved in this operation.
|
||||
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(
|
||||
this.TYPE, this.NAME, this.variableDefinitions, this.selectionSet) {
|
||||
assert(TYPE == null ||
|
||||
TYPE.text == 'query' ||
|
||||
TYPE.text == 'mutation' ||
|
||||
TYPE.text == 'subscription');
|
||||
/// Use [nameToken] instead.
|
||||
@deprecated
|
||||
Token get NAME => nameToken;
|
||||
|
||||
/// Use [typeToken] instead.
|
||||
@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
|
||||
FileSpan get span {
|
||||
if (TYPE == null) return selectionSet.span;
|
||||
var out = NAME == null ? TYPE.span : TYPE.span.expand(NAME.span);
|
||||
if (typeToken == null) return selectionSet.span;
|
||||
var out = nameToken == null
|
||||
? typeToken.span
|
||||
: typeToken.span.expand(nameToken.span);
|
||||
out = directives.fold<FileSpan>(out, (o, d) => o.expand(d.span));
|
||||
return out.expand(selectionSet.span);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue