Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide single-character locations for selection parse errors #6241

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions apollo-federation/src/sources/connect/validation/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -115,26 +114,25 @@ 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(),
})?;

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(),
})?;
Expand All @@ -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(),
});
Expand Down