From 917477cb890af6de927ab30e28acd17a21b0ee6b Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 14 Aug 2019 10:59:18 -0400 Subject: [PATCH] Remove use of deprecated value members --- graphql_server/lib/graphql_server.dart | 55 ++++++++++++++------------ graphql_server/lib/introspection.dart | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/graphql_server/lib/graphql_server.dart b/graphql_server/lib/graphql_server.dart index 796422af..09336492 100644 --- a/graphql_server/lib/graphql_server.dart +++ b/graphql_server/lib/graphql_server.dart @@ -55,7 +55,7 @@ class GraphQL { GraphQLType convertType(TypeContext ctx) { if (ctx.listType != null) { - return GraphQLListType(convertType(ctx.listType.type)); + return GraphQLListType(convertType(ctx.listType.innerType)); } else if (ctx.typeName != null) { switch (ctx.typeName.name) { case 'Int': @@ -161,7 +161,8 @@ class GraphQL { if (value == null) { if (defaultValue != null) { - coercedValues[variableName] = defaultValue.value.value; + coercedValues[variableName] = + defaultValue.value.computeValue(variableValues); } else if (!variableType.isNullable) { throw GraphQLException.fromSourceSpan( 'Missing required variable "$variableName".', @@ -400,11 +401,11 @@ class GraphQL { var argumentType = argumentDefinition.type; var defaultValue = argumentDefinition.defaultValue; - var value = argumentValues.firstWhere((a) => a.name == argumentName, - orElse: () => null); + var argumentValue = argumentValues + .firstWhere((a) => a.name == argumentName, orElse: () => null); - if (value?.valueOrVariable?.variable != null) { - var variableName = value.valueOrVariable.variable.name; + if (argumentValue.value is VariableContext) { + var variableName = (argumentValue.value as VariableContext).name; var variableValue = variableValues[variableName]; if (variableValues.containsKey(variableName)) { @@ -414,11 +415,11 @@ class GraphQL { } else if (argumentType is GraphQLNonNullableType) { throw GraphQLException.fromSourceSpan( 'Missing value for argument "$argumentName" of field "$fieldName".', - value.valueOrVariable.span); + argumentValue.value.span); } else { continue; } - } else if (value == null) { + } else if (argumentValue == null) { if (defaultValue != null || argumentDefinition.defaultsToNull) { coercedValues[argumentName] = defaultValue; } else if (argumentType is GraphQLNonNullableType) { @@ -430,7 +431,7 @@ class GraphQL { } else { try { var validation = argumentType.validate( - fieldName, value.valueOrVariable.value.value); + fieldName, argumentValue.value.computeValue(variableValues)); if (!validation.successful) { var errors = [ @@ -438,7 +439,7 @@ class GraphQL { 'Type coercion error for value of argument "$argumentName" of field "$fieldName".', locations: [ GraphExceptionErrorLocation.fromSourceLocation( - value.valueOrVariable.span.start) + argumentValue.value.span.start) ], ) ]; @@ -449,7 +450,7 @@ class GraphQL { error, locations: [ 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".', locations: [ GraphExceptionErrorLocation.fromSourceLocation( - value.valueOrVariable.span.start) + argumentValue.value.span.start) ], ), GraphQLExceptionError( e.message.toString(), locations: [ GraphExceptionErrorLocation.fromSourceLocation( - value.valueOrVariable.span.start) + argumentValue.value.span.start) ], ), ]); @@ -699,25 +700,27 @@ class GraphQL { SelectionContext selection, Map variableValues) { if (selection.field == null) return null; var directive = selection.field.directives.firstWhere((d) { - var vv = d.valueOrVariable; - if (vv.value != null) return vv.value.value == name; - return vv.variable.name == name; + var vv = d.value; + if (vv is VariableContext) { + return vv.name == name; + } else { + return vv.computeValue(variableValues) == name; + } }, orElse: () => null); if (directive == null) return null; if (directive.argument?.name != argumentName) return null; - var vv = directive.argument.valueOrVariable; - - if (vv.value != null) return vv.value.value; - - var vname = vv.variable.name; - if (!variableValues.containsKey(vname)) { - throw GraphQLException.fromSourceSpan( - 'Unknown variable: "$vname"', vv.span); + var vv = directive.argument.value; + if (vv is VariableContext) { + var vname = vv.name; + if (!variableValues.containsKey(vname)) { + throw GraphQLException.fromSourceSpan( + 'Unknown variable: "$vname"', vv.span); + } + return variableValues[vname]; } - - return variableValues[vname]; + return vv.computeValue(variableValues); } bool doesFragmentTypeApply( diff --git a/graphql_server/lib/introspection.dart b/graphql_server/lib/introspection.dart index 8ccd68da..47604f61 100644 --- a/graphql_server/lib/introspection.dart +++ b/graphql_server/lib/introspection.dart @@ -382,7 +382,7 @@ GraphQLObjectType _reflectDirectiveType() { field( 'name', graphQLString.nonNullable(), - resolve: (obj, _) => (obj as DirectiveContext).NAME.span.text, + resolve: (obj, _) => (obj as DirectiveContext).nameToken.span.text, ), field( 'description',