pedantic: misc_value
This commit is contained in:
parent
c83c9e1fc3
commit
84080c4fe3
2 changed files with 55 additions and 20 deletions
|
@ -3,46 +3,68 @@ import '../token.dart';
|
||||||
import 'input_value.dart';
|
import 'input_value.dart';
|
||||||
import 'node.dart';
|
import 'node.dart';
|
||||||
|
|
||||||
|
/// A GraphQL `null` literal.
|
||||||
class NullValueContext extends InputValueContext<Null> {
|
class NullValueContext extends InputValueContext<Null> {
|
||||||
final Token NULL;
|
/// The source token.
|
||||||
|
final Token nullToken;
|
||||||
|
|
||||||
NullValueContext(this.NULL);
|
NullValueContext(this.nullToken);
|
||||||
|
|
||||||
|
/// Use [nullToken] instead.
|
||||||
|
@deprecated
|
||||||
|
Token get NULL => nullToken;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FileSpan get span => NULL.span;
|
FileSpan get span => nullToken.span;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Null computeValue(Map<String, dynamic> variables) => null;
|
Null computeValue(Map<String, dynamic> variables) => null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A GraphQL enumeration literal.
|
||||||
class EnumValueContext extends InputValueContext<String> {
|
class EnumValueContext extends InputValueContext<String> {
|
||||||
final Token NAME;
|
/// The source token.
|
||||||
|
final Token nameToken;
|
||||||
|
|
||||||
EnumValueContext(this.NAME);
|
EnumValueContext(this.nameToken);
|
||||||
|
|
||||||
|
/// Use [nameToken] instead.
|
||||||
|
@deprecated
|
||||||
|
Token get NAME => nameToken;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FileSpan get span => NAME.span;
|
FileSpan get span => nameToken.span;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String computeValue(Map<String, dynamic> variables) => NAME.span.text;
|
String computeValue(Map<String, dynamic> variables) => nameToken.span.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A GraphQL object literal.
|
||||||
class ObjectValueContext extends InputValueContext<Map<String, dynamic>> {
|
class ObjectValueContext extends InputValueContext<Map<String, dynamic>> {
|
||||||
final Token LBRACE;
|
/// The source tokens.
|
||||||
final List<ObjectFieldContext> fields;
|
final Token lBraceToken, rBraceToken;
|
||||||
final Token RBRACE;
|
|
||||||
|
|
||||||
ObjectValueContext(this.LBRACE, this.fields, this.RBRACE);
|
/// The fields in the object.
|
||||||
|
final List<ObjectFieldContext> fields;
|
||||||
|
|
||||||
|
ObjectValueContext(this.lBraceToken, this.fields, this.rBraceToken);
|
||||||
|
|
||||||
|
/// Use [lBraceToken] instead.
|
||||||
|
Token get LBRACE => lBraceToken;
|
||||||
|
|
||||||
|
/// Use [rBraceToken] instead.
|
||||||
|
@deprecated
|
||||||
|
Token get RBRACE => rBraceToken;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FileSpan get span {
|
FileSpan get span {
|
||||||
var left = LBRACE.span;
|
var left = lBraceToken.span;
|
||||||
|
|
||||||
for (var field in fields) {
|
for (var field in fields) {
|
||||||
left = left.expand(field.span);
|
left = left.expand(field.span);
|
||||||
}
|
}
|
||||||
|
|
||||||
return left.expand(RBRACE.span);
|
return left.expand(rBraceToken.span);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -52,19 +74,32 @@ class ObjectValueContext extends InputValueContext<Map<String, dynamic>> {
|
||||||
} else {
|
} else {
|
||||||
return fields.fold<Map<String, dynamic>>(<String, dynamic>{},
|
return fields.fold<Map<String, dynamic>>(<String, dynamic>{},
|
||||||
(map, field) {
|
(map, field) {
|
||||||
return map..[field.NAME.text] = field.value.computeValue(variables);
|
return map
|
||||||
|
..[field.nameToken.text] = field.value.computeValue(variables);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A field within an [ObjectValueContext].
|
||||||
class ObjectFieldContext extends Node {
|
class ObjectFieldContext extends Node {
|
||||||
final Token NAME;
|
/// The source tokens.
|
||||||
final Token COLON;
|
final Token nameToken, colonToken;
|
||||||
|
|
||||||
|
/// The associated value.
|
||||||
final InputValueContext value;
|
final InputValueContext value;
|
||||||
|
|
||||||
ObjectFieldContext(this.NAME, this.COLON, this.value);
|
ObjectFieldContext(this.nameToken, this.colonToken, this.value);
|
||||||
|
|
||||||
|
/// Use [nameToken] instead.
|
||||||
|
@deprecated
|
||||||
|
Token get NAME => nameToken;
|
||||||
|
|
||||||
|
/// Use [colonToken] instead.
|
||||||
|
@deprecated
|
||||||
|
Token get COLON => colonToken;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FileSpan get span => NAME.span.expand(COLON.span).expand(value.span);
|
FileSpan get span =>
|
||||||
|
nameToken.span.expand(colonToken.span).expand(value.span);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,8 @@ void main() {
|
||||||
expect(condition.name, 'condition');
|
expect(condition.name, 'condition');
|
||||||
expect(condition.value, TypeMatcher<ObjectValueContext>());
|
expect(condition.value, TypeMatcher<ObjectValueContext>());
|
||||||
var conditionValue = condition.value as ObjectValueContext;
|
var conditionValue = condition.value as ObjectValueContext;
|
||||||
var memberId =
|
var memberId = conditionValue.fields
|
||||||
conditionValue.fields.singleWhere((f) => f.NAME.text == 'memberId');
|
.singleWhere((f) => f.nameToken.text == 'memberId');
|
||||||
expect(memberId.value, TypeMatcher<T>());
|
expect(memberId.value, TypeMatcher<T>());
|
||||||
print('Found \$memberId: Instance of $T');
|
print('Found \$memberId: Instance of $T');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue