diff --git a/apollo-federation/src/sources/connect/validation/selection.rs b/apollo-federation/src/sources/connect/validation/selection.rs index ebbb6eb143..ac90693a5c 100644 --- a/apollo-federation/src/sources/connect/validation/selection.rs +++ b/apollo-federation/src/sources/connect/validation/selection.rs @@ -4,7 +4,6 @@ use std::ops::Range; use apollo_compiler::ast::FieldDefinition; use apollo_compiler::collections::IndexSet; use apollo_compiler::parser::LineColumn; -use apollo_compiler::parser::SourceMap; use apollo_compiler::schema::Component; use apollo_compiler::schema::Directive; use apollo_compiler::schema::ExtendedType; @@ -36,7 +35,7 @@ pub(super) fn validate_selection( schema: &SchemaInfo, seen_fields: &mut IndexSet<(Name, Name)>, ) -> Result<(), Message> { - let (selection_arg, json_selection) = get_json_selection(coordinate, &schema.sources)?; + let (selection_arg, json_selection) = get_json_selection(coordinate, schema)?; let field = coordinate.field_coordinate.field; let Some(return_type) = schema.get_object(field.ty.inner_named_type()) else { @@ -102,7 +101,7 @@ pub(super) fn validate_body_selection( fn get_json_selection<'a>( connect_directive: ConnectDirectiveCoordinate<'a>, - source_map: &'a SourceMap, + schema: &'a SchemaInfo<'a>, ) -> Result<(SelectionArg<'a>, JSONSelection), Message> { let coordinate = SelectionCoordinate::from(connect_directive); let selection_arg = connect_directive @@ -115,16 +114,16 @@ fn get_json_selection<'a>( message: format!("{coordinate} is required."), locations: connect_directive .directive - .line_column_range(source_map) + .line_column_range(&schema.sources) .into_iter() .collect(), })?; let selection_str = - GraphQLString::new(&selection_arg.value, source_map).map_err(|_| Message { + GraphQLString::new(&selection_arg.value, &schema.sources).map_err(|_| Message { code: Code::GraphQLError, message: format!("{coordinate} must be a string."), locations: selection_arg - .line_column_range(source_map) + .line_column_range(&schema.sources) .into_iter() .collect(), })?; @@ -132,9 +131,8 @@ fn get_json_selection<'a>( let selection = JSONSelection::parse(selection_str.as_str()).map_err(|err| Message { code: Code::InvalidJsonSelection, message: format!("{coordinate} is not a valid JSONSelection: {err}",), - locations: selection_arg - .value - .line_column_range(source_map) + locations: selection_str + .line_col_for_subslice(err.offset..err.offset + 1, schema) .into_iter() .collect(), })?; @@ -145,7 +143,7 @@ fn get_json_selection<'a>( message: format!("{coordinate} is empty",), locations: selection_arg .value - .line_column_range(source_map) + .line_column_range(&schema.sources) .into_iter() .collect(), });