diff --git a/graphql_parser/lib/src/language/ast/misc_value.dart b/graphql_parser/lib/src/language/ast/misc_value.dart index 0aa1facb..9307e4c1 100644 --- a/graphql_parser/lib/src/language/ast/misc_value.dart +++ b/graphql_parser/lib/src/language/ast/misc_value.dart @@ -3,46 +3,68 @@ import '../token.dart'; import 'input_value.dart'; import 'node.dart'; +/// A GraphQL `null` literal. class NullValueContext extends InputValueContext { - final Token NULL; + /// The source token. + final Token nullToken; - NullValueContext(this.NULL); + NullValueContext(this.nullToken); + + /// Use [nullToken] instead. + @deprecated + Token get NULL => nullToken; @override - FileSpan get span => NULL.span; + FileSpan get span => nullToken.span; @override Null computeValue(Map variables) => null; } +/// A GraphQL enumeration literal. class EnumValueContext extends InputValueContext { - final Token NAME; + /// The source token. + final Token nameToken; - EnumValueContext(this.NAME); + EnumValueContext(this.nameToken); + + /// Use [nameToken] instead. + @deprecated + Token get NAME => nameToken; @override - FileSpan get span => NAME.span; + FileSpan get span => nameToken.span; @override - String computeValue(Map variables) => NAME.span.text; + String computeValue(Map variables) => nameToken.span.text; } +/// A GraphQL object literal. class ObjectValueContext extends InputValueContext> { - final Token LBRACE; - final List fields; - final Token RBRACE; + /// The source tokens. + final Token lBraceToken, rBraceToken; - ObjectValueContext(this.LBRACE, this.fields, this.RBRACE); + /// The fields in the object. + final List fields; + + ObjectValueContext(this.lBraceToken, this.fields, this.rBraceToken); + + /// Use [lBraceToken] instead. + Token get LBRACE => lBraceToken; + + /// Use [rBraceToken] instead. + @deprecated + Token get RBRACE => rBraceToken; @override FileSpan get span { - var left = LBRACE.span; + var left = lBraceToken.span; for (var field in fields) { left = left.expand(field.span); } - return left.expand(RBRACE.span); + return left.expand(rBraceToken.span); } @override @@ -52,19 +74,32 @@ class ObjectValueContext extends InputValueContext> { } else { return fields.fold>({}, (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 { - final Token NAME; - final Token COLON; + /// The source tokens. + final Token nameToken, colonToken; + + /// The associated 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 - FileSpan get span => NAME.span.expand(COLON.span).expand(value.span); + FileSpan get span => + nameToken.span.expand(colonToken.span).expand(value.span); } diff --git a/graphql_parser/test/issue23_test.dart b/graphql_parser/test/issue23_test.dart index aa64175b..6ab4950a 100644 --- a/graphql_parser/test/issue23_test.dart +++ b/graphql_parser/test/issue23_test.dart @@ -48,8 +48,8 @@ void main() { expect(condition.name, 'condition'); expect(condition.value, TypeMatcher()); var conditionValue = condition.value as ObjectValueContext; - var memberId = - conditionValue.fields.singleWhere((f) => f.NAME.text == 'memberId'); + var memberId = conditionValue.fields + .singleWhere((f) => f.nameToken.text == 'memberId'); expect(memberId.value, TypeMatcher()); print('Found \$memberId: Instance of $T'); });