Remove use of deprecated value members

This commit is contained in:
Tobe O 2019-08-14 10:59:18 -04:00
parent 02a816f5dd
commit 917477cb89
2 changed files with 30 additions and 27 deletions

View file

@ -55,7 +55,7 @@ class GraphQL {
GraphQLType convertType(TypeContext ctx) { GraphQLType convertType(TypeContext ctx) {
if (ctx.listType != null) { if (ctx.listType != null) {
return GraphQLListType(convertType(ctx.listType.type)); return GraphQLListType(convertType(ctx.listType.innerType));
} else if (ctx.typeName != null) { } else if (ctx.typeName != null) {
switch (ctx.typeName.name) { switch (ctx.typeName.name) {
case 'Int': case 'Int':
@ -161,7 +161,8 @@ class GraphQL {
if (value == null) { if (value == null) {
if (defaultValue != null) { if (defaultValue != null) {
coercedValues[variableName] = defaultValue.value.value; coercedValues[variableName] =
defaultValue.value.computeValue(variableValues);
} else if (!variableType.isNullable) { } else if (!variableType.isNullable) {
throw GraphQLException.fromSourceSpan( throw GraphQLException.fromSourceSpan(
'Missing required variable "$variableName".', 'Missing required variable "$variableName".',
@ -400,11 +401,11 @@ class GraphQL {
var argumentType = argumentDefinition.type; var argumentType = argumentDefinition.type;
var defaultValue = argumentDefinition.defaultValue; var defaultValue = argumentDefinition.defaultValue;
var value = argumentValues.firstWhere((a) => a.name == argumentName, var argumentValue = argumentValues
orElse: () => null); .firstWhere((a) => a.name == argumentName, orElse: () => null);
if (value?.valueOrVariable?.variable != null) { if (argumentValue.value is VariableContext) {
var variableName = value.valueOrVariable.variable.name; var variableName = (argumentValue.value as VariableContext).name;
var variableValue = variableValues[variableName]; var variableValue = variableValues[variableName];
if (variableValues.containsKey(variableName)) { if (variableValues.containsKey(variableName)) {
@ -414,11 +415,11 @@ class GraphQL {
} else if (argumentType is GraphQLNonNullableType) { } else if (argumentType is GraphQLNonNullableType) {
throw GraphQLException.fromSourceSpan( throw GraphQLException.fromSourceSpan(
'Missing value for argument "$argumentName" of field "$fieldName".', 'Missing value for argument "$argumentName" of field "$fieldName".',
value.valueOrVariable.span); argumentValue.value.span);
} else { } else {
continue; continue;
} }
} else if (value == null) { } else if (argumentValue == null) {
if (defaultValue != null || argumentDefinition.defaultsToNull) { if (defaultValue != null || argumentDefinition.defaultsToNull) {
coercedValues[argumentName] = defaultValue; coercedValues[argumentName] = defaultValue;
} else if (argumentType is GraphQLNonNullableType) { } else if (argumentType is GraphQLNonNullableType) {
@ -430,7 +431,7 @@ class GraphQL {
} else { } else {
try { try {
var validation = argumentType.validate( var validation = argumentType.validate(
fieldName, value.valueOrVariable.value.value); fieldName, argumentValue.value.computeValue(variableValues));
if (!validation.successful) { if (!validation.successful) {
var errors = <GraphQLExceptionError>[ var errors = <GraphQLExceptionError>[
@ -438,7 +439,7 @@ class GraphQL {
'Type coercion error for value of argument "$argumentName" of field "$fieldName".', 'Type coercion error for value of argument "$argumentName" of field "$fieldName".',
locations: [ locations: [
GraphExceptionErrorLocation.fromSourceLocation( GraphExceptionErrorLocation.fromSourceLocation(
value.valueOrVariable.span.start) argumentValue.value.span.start)
], ],
) )
]; ];
@ -449,7 +450,7 @@ class GraphQL {
error, error,
locations: [ locations: [
GraphExceptionErrorLocation.fromSourceLocation( GraphExceptionErrorLocation.fromSourceLocation(
value.valueOrVariable.span.start) argumentValue.value.span.start)
], ],
), ),
); );
@ -466,14 +467,14 @@ class GraphQL {
'Type coercion error for value of argument "$argumentName" of field "$fieldName".', 'Type coercion error for value of argument "$argumentName" of field "$fieldName".',
locations: [ locations: [
GraphExceptionErrorLocation.fromSourceLocation( GraphExceptionErrorLocation.fromSourceLocation(
value.valueOrVariable.span.start) argumentValue.value.span.start)
], ],
), ),
GraphQLExceptionError( GraphQLExceptionError(
e.message.toString(), e.message.toString(),
locations: [ locations: [
GraphExceptionErrorLocation.fromSourceLocation( GraphExceptionErrorLocation.fromSourceLocation(
value.valueOrVariable.span.start) argumentValue.value.span.start)
], ],
), ),
]); ]);
@ -699,26 +700,28 @@ class GraphQL {
SelectionContext selection, Map<String, dynamic> variableValues) { SelectionContext selection, Map<String, dynamic> variableValues) {
if (selection.field == null) return null; if (selection.field == null) return null;
var directive = selection.field.directives.firstWhere((d) { var directive = selection.field.directives.firstWhere((d) {
var vv = d.valueOrVariable; var vv = d.value;
if (vv.value != null) return vv.value.value == name; if (vv is VariableContext) {
return vv.variable.name == name; return vv.name == name;
} else {
return vv.computeValue(variableValues) == name;
}
}, orElse: () => null); }, orElse: () => null);
if (directive == null) return null; if (directive == null) return null;
if (directive.argument?.name != argumentName) return null; if (directive.argument?.name != argumentName) return null;
var vv = directive.argument.valueOrVariable; var vv = directive.argument.value;
if (vv is VariableContext) {
if (vv.value != null) return vv.value.value; var vname = vv.name;
var vname = vv.variable.name;
if (!variableValues.containsKey(vname)) { if (!variableValues.containsKey(vname)) {
throw GraphQLException.fromSourceSpan( throw GraphQLException.fromSourceSpan(
'Unknown variable: "$vname"', vv.span); 'Unknown variable: "$vname"', vv.span);
} }
return variableValues[vname]; return variableValues[vname];
} }
return vv.computeValue(variableValues);
}
bool doesFragmentTypeApply( bool doesFragmentTypeApply(
GraphQLObjectType objectType, TypeConditionContext fragmentType) { GraphQLObjectType objectType, TypeConditionContext fragmentType) {

View file

@ -382,7 +382,7 @@ GraphQLObjectType _reflectDirectiveType() {
field( field(
'name', 'name',
graphQLString.nonNullable(), graphQLString.nonNullable(),
resolve: (obj, _) => (obj as DirectiveContext).NAME.span.text, resolve: (obj, _) => (obj as DirectiveContext).nameToken.span.text,
), ),
field( field(
'description', 'description',